From 64f16474f8331154fcd7b5bab593f62ee60f81a9 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 19 Jul 2019 10:16:40 -0700 Subject: [PATCH 1/3] fix double slash conundrum --- common/step_download.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/common/step_download.go b/common/step_download.go index cc076a182..853501859 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -171,12 +171,20 @@ 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()) + } 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, From 197a283b5ecddc38ccbaf7c459510792ec4945d2 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Fri, 19 Jul 2019 10:35:50 -0700 Subject: [PATCH 2/3] actually check for filepath being present --- common/step_download.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/common/step_download.go b/common/step_download.go index 853501859..e3ff8cc2e 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -178,6 +178,11 @@ func (s *StepDownload) download(ctx context.Context, ui packer.Ui, source string // 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 actually present on system so it must be some + // other weird thing; see if go-getter can figure it out. + src = u.String() + } } ui.Say(fmt.Sprintf("Trying %s", u.String())) From e9549d2688aa33fe9583a275c2bdae221ad6d011 Mon Sep 17 00:00:00 2001 From: Megan Marsh Date: Mon, 22 Jul 2019 09:17:48 -0700 Subject: [PATCH 3/3] add test for local fs download --- common/step_download.go | 5 +++-- common/step_download_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/common/step_download.go b/common/step_download.go index e3ff8cc2e..ab75f3392 100644 --- a/common/step_download.go +++ b/common/step_download.go @@ -179,8 +179,9 @@ func (s *StepDownload) download(ctx context.Context, ui packer.Ui, source string // 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 actually present on system so it must be some - // other weird thing; see if go-getter can figure it out. + // 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() } } 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,