diff --git a/common/step_download.go b/common/step_download.go index cc076a182..ab75f3392 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -171,12 +171,26 @@ func (s *StepDownload) download(ctx context.Context, ui packer.Ui, source string // could guess it only in cases it is // necessary. } + src := u.String() + if u.Scheme == "" || strings.ToLower(u.Scheme) == "file" { + // If a local filepath, then we need to preprocess to make sure the + // path doens't have any multiple successive path separators; if it + // does, go-getter will read this as a specialized go-getter-specific + // subdirectory command, which it most likely isn't. + src = filepath.Clean(u.String()) + if _, err := os.Stat(filepath.Clean(u.Path)); err != nil { + // Cleaned path isn't present on system so it must be some other + // scheme. Don't error right away; see if go-getter can figure it + // out. + src = u.String() + } + } ui.Say(fmt.Sprintf("Trying %s", u.String())) gc := getter.Client{ Ctx: ctx, Dst: targetPath, - Src: u.String(), + Src: src, ProgressListener: ui, Pwd: wd, Dir: false, diff --git a/common/step_download_test.go b/common/step_download_test.go index 8a8df9960..6a5a70bd8 100644 --- a/common/step_download_test.go +++ b/common/step_download_test.go @@ -71,6 +71,14 @@ func TestStepDownload_Run(t *testing.T) { toSha1(abs(t, "./test-fixtures/root/another.txt")) + ".lock", }, }, + {"double slashes on a local filesystem passes", + fields{Url: []string{abs(t, "./test-fixtures/root//another.txt")}}, + multistep.ActionContinue, + []string{ + toSha1(abs(t, "./test-fixtures/root//another.txt")), + toSha1(abs(t, "./test-fixtures/root//another.txt")) + ".lock", + }, + }, {"none checksum works, without a checksum", fields{Url: []string{abs(t, "./test-fixtures/root/another.txt")}, ChecksumType: "none"}, multistep.ActionContinue,