Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
c06c1fee
Commit
c06c1fee
authored
Jul 29, 2013
by
Mitchell Hashimoto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
builder/common: make rel path absolute in DownloadableURL [GH-215]
parent
8db53905
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
5 deletions
+25
-5
builder/common/config.go
builder/common/config.go
+13
-0
builder/common/config_test.go
builder/common/config_test.go
+12
-5
No files found.
builder/common/config.go
View file @
c06c1fee
...
...
@@ -2,6 +2,7 @@ package common
import
(
"fmt"
"path/filepath"
"github.com/mitchellh/mapstructure"
"github.com/mitchellh/packer/packer"
"net/url"
...
...
@@ -75,6 +76,18 @@ func DownloadableURL(original string) (string, error) {
if
_
,
err
:=
os
.
Stat
(
url
.
Path
);
err
!=
nil
{
return
""
,
err
}
url
.
Path
,
err
=
filepath
.
Abs
(
url
.
Path
)
if
err
!=
nil
{
return
""
,
err
}
url
.
Path
,
err
=
filepath
.
EvalSymlinks
(
url
.
Path
)
if
err
!=
nil
{
return
""
,
err
}
url
.
Path
=
filepath
.
Clean
(
url
.
Path
)
}
// Make sure it is lowercased
...
...
builder/common/config_test.go
View file @
c06c1fee
...
...
@@ -98,6 +98,13 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
defer
os
.
Remove
(
tf
.
Name
())
tf
.
Close
()
tfPath
,
err
:=
filepath
.
EvalSymlinks
(
tf
.
Name
())
if
err
!=
nil
{
t
.
Fatalf
(
"tempfile err: %s"
,
err
)
}
tfPath
=
filepath
.
Clean
(
tfPath
)
// Relative filepath. We run this test in a func so that
// the defers run right away.
func
()
{
...
...
@@ -106,19 +113,19 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
t
.
Fatalf
(
"getwd err: %s"
,
err
)
}
err
=
os
.
Chdir
(
filepath
.
Dir
(
tf
.
Name
()
))
err
=
os
.
Chdir
(
filepath
.
Dir
(
tf
Path
))
if
err
!=
nil
{
t
.
Fatalf
(
"chdir err: %s"
,
err
)
}
defer
os
.
Chdir
(
wd
)
filename
:=
filepath
.
Base
(
tf
.
Name
()
)
filename
:=
filepath
.
Base
(
tf
Path
)
u
,
err
:=
DownloadableURL
(
filename
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
u
!=
fmt
.
Sprintf
(
"file://
/%s"
,
filename
)
{
if
u
!=
fmt
.
Sprintf
(
"file://
%s"
,
tfPath
)
{
t
.
Fatalf
(
"unexpected: %s"
,
u
)
}
}()
...
...
@@ -132,12 +139,12 @@ func TestDownloadableURL_FilePaths(t *testing.T) {
}
// Good file
u
,
err
:=
DownloadableURL
(
prefix
+
tf
.
Name
()
)
u
,
err
:=
DownloadableURL
(
prefix
+
tf
Path
)
if
err
!=
nil
{
t
.
Fatalf
(
"err: %s"
,
err
)
}
if
u
!=
fmt
.
Sprintf
(
"file://%s"
,
tf
.
Name
()
)
{
if
u
!=
fmt
.
Sprintf
(
"file://%s"
,
tf
Path
)
{
t
.
Fatalf
(
"unexpected: %s"
,
u
)
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment