Skip to content

Commit

Permalink
fix: normalizePath function to standardize the paths correctly
Browse files Browse the repository at this point in the history
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 moby#4696

Signed-off-by: Anthony Nandaa <profnandaa@gmail.com>
  • Loading branch information
profnandaa committed Apr 5, 2024
1 parent dc23e43 commit 468fbe9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
3 changes: 3 additions & 0 deletions client/llb/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
_ "crypto/sha256" // for opencontainers/go-digest
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion solver/llbsolver/file/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down

0 comments on commit 468fbe9

Please sign in to comment.