Skip to content

Commit

Permalink
Fix filepath.Clean for file prefixed URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
Wilken Rivera committed Oct 13, 2023
1 parent 2ed94e4 commit 7587a60
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions multistep/commonsteps/step_download.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,11 +221,16 @@ func (s *StepDownload) download(ctx context.Context, ui packersdk.Ui, source str
}
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
// If a local filepath, then we need to pre-process to make sure the
// path doesn'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())
// Starting with Go 1.21.0 filepath.Clean on Windows treats paths containing file: as invalid
// so they are prefixed with a dot (.) followed by the os.PathSeparator
if runtime.GOOS == "windows" && (src[0] == '.' && os.IsPathSeparator(src[1])) {
src = src[2:]
}
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
Expand Down

0 comments on commit 7587a60

Please sign in to comment.