From 468fbe9bd79bde9931313532684998b51ee3330e Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Fri, 5 Apr 2024 14:32:58 +0300 Subject: [PATCH] fix: normalizePath function to standardize the paths correctly We have an edge case situation coming from a path like C:\\ The drive letter is stipped out and \\ remains and therefore appended with / to get `/\\`. normalizePath is suppposed to also standardize this path to unix format and it wasn't doing so, the path was returning as is. With this minor fix, `/` will be returned instead. fixes #4696 Signed-off-by: Anthony Nandaa --- client/llb/fileop.go | 3 +++ solver/llbsolver/file/backend.go | 2 +- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/client/llb/fileop.go b/client/llb/fileop.go index 831c4f381edd7..b57b8463d89fb 100644 --- a/client/llb/fileop.go +++ b/client/llb/fileop.go @@ -5,6 +5,7 @@ import ( _ "crypto/sha256" // for opencontainers/go-digest "os" "path" + "path/filepath" "strconv" "strings" "time" @@ -801,6 +802,8 @@ func (f *FileOp) Marshal(ctx context.Context, c *Constraints) (digest.Digest, [] func normalizePath(parent, p string, keepSlash bool) string { origPath := p + // first, normalize everything to unix path + p = filepath.ToSlash(p) p = path.Clean(p) if !path.IsAbs(p) { p = path.Join("/", parent, p) diff --git a/solver/llbsolver/file/backend.go b/solver/llbsolver/file/backend.go index 293caa1082bd9..58b489cb8a286 100644 --- a/solver/llbsolver/file/backend.go +++ b/solver/llbsolver/file/backend.go @@ -139,7 +139,7 @@ func docopy(ctx context.Context, src, dest string, action pb.FileActionCopy, u * } destPath, err := cleanPath(action.Dest) if err != nil { - return errors.Wrap(err, "cleaning path") + return errors.Wrap(err, "cleaning destination path") } if !action.CreateDestPath { p, err := fs.RootPath(dest, filepath.Join("/", action.Dest))