From 018155fa68e3ab267588f4f1735532bcfb7f02aa Mon Sep 17 00:00:00 2001 From: Anthony Nandaa Date: Fri, 5 Apr 2024 14:32:58 +0300 Subject: [PATCH] fix: use unix path separator since path already normalized In the case for Windows, this line at frontend/dockerfile/dockerfile2llb/convert.go#L1142 ```go dest += string(filepath.Separator) ``` was adding the `\\` to a path that is already normalized to unix-format, hence ending up with dest paths like `/\\` for `C:\\` and `/test\\` for `C:\\test\\`. the src paths are well normalized too at ~L1290. This change removes the block of code and instead does the "/" appending using the keepSlash logic that is in system.NormalizePath called in pathRelativeToWorkingDir() function before. fixes #4696 Signed-off-by: Anthony Nandaa --- frontend/dockerfile/dockerfile2llb/convert.go | 8 ++------ solver/llbsolver/file/backend.go | 2 +- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index ea5e8601536b..a0dd97aac627 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -1138,10 +1138,6 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { return err } - if cfg.params.DestPath == "." || cfg.params.DestPath == "" || cfg.params.DestPath[len(cfg.params.DestPath)-1] == filepath.Separator { - dest += string(filepath.Separator) - } - var copyOpt []llb.CopyOption if cfg.chown != "" { @@ -1562,9 +1558,9 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform) } if system.IsAbs(p, platform.OS) { - return system.NormalizePath("/", p, platform.OS, false) + return system.NormalizePath("/", p, platform.OS, true) } - return system.NormalizePath(dir, p, platform.OS, false) + return system.NormalizePath(dir, p, platform.OS, true) } func addEnv(env []string, k, v string) []string { diff --git a/solver/llbsolver/file/backend.go b/solver/llbsolver/file/backend.go index 293caa1082bd..58b489cb8a28 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))