From 02c144e5e98fab8c2dc1a767d69d2664c9916c68 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. fixes #4696 Signed-off-by: Anthony Nandaa --- frontend/dockerfile/dockerfile2llb/convert.go | 5 ++++- solver/llbsolver/file/backend.go | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/frontend/dockerfile/dockerfile2llb/convert.go b/frontend/dockerfile/dockerfile2llb/convert.go index ea5e8601536ba..e11da2eb69ebc 100644 --- a/frontend/dockerfile/dockerfile2llb/convert.go +++ b/frontend/dockerfile/dockerfile2llb/convert.go @@ -1139,7 +1139,10 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error { } if cfg.params.DestPath == "." || cfg.params.DestPath == "" || cfg.params.DestPath[len(cfg.params.DestPath)-1] == filepath.Separator { - dest += string(filepath.Separator) + // can use unix path separator since + // at this point, Windows dest path is already normalized + // in `pathRelativeToWorkingDir` above. + dest += "/" } var copyOpt []llb.CopyOption 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))