Skip to content

Commit

Permalink
Fix various nits
Browse files Browse the repository at this point in the history
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
  • Loading branch information
gabriel-samfira committed Jul 10, 2023
1 parent 69f2c06 commit b829c52
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 9 deletions.
5 changes: 1 addition & 4 deletions client/llb/fileop.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
_ "crypto/sha256" // for opencontainers/go-digest
"os"
"path"
"path/filepath"
"strconv"
"strings"
"time"
Expand Down Expand Up @@ -523,9 +522,7 @@ func (a *fileActionCopy) toProtoAction(ctx context.Context, parent string, base
}

func (a *fileActionCopy) sourcePath(ctx context.Context) (string, error) {
// filepath.Clean() also does a filepath.FromSlash(). Explicitly convert back to UNIX path
// separators.
p := filepath.ToSlash(filepath.Clean(a.src))
p := path.Clean(a.src)
dir := "/"
var err error
if !path.IsAbs(p) {
Expand Down
6 changes: 3 additions & 3 deletions frontend/dockerfile/dockerfile2llb/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -1185,7 +1185,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
}}, copyOpt...)

if a == nil {
a = llb.Copy(st, filepath.ToSlash(f), dest, opts...)
a = llb.Copy(st, system.ToSlash(f, d.platform.OS), dest, opts...)
} else {
a = a.Copy(st, filepath.ToSlash(f), dest, opts...)
}
Expand Down Expand Up @@ -1423,11 +1423,11 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform)
}
p, err = system.CheckSystemDriveAndRemoveDriveLetter(p, platform.OS)
if err != nil {
return "", errors.Wrap(err, "remving drive letter")
return "", errors.Wrap(err, "removing drive letter")
}

if system.IsAbs(p, platform.OS) {
return p, nil
return system.NormalizePath("/", p, platform.OS, false)
}
return system.NormalizePath(dir, p, platform.OS, false)
}
Expand Down
5 changes: 3 additions & 2 deletions solver/llbsolver/file/backend.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,13 +352,14 @@ func cleanPath(s string) (string, error) {
if err != nil {
return "", errors.Wrap(err, "removing drive letter")
}
s = filepath.FromSlash(s)
s2 := filepath.Join("/", s)
if strings.HasSuffix(filepath.FromSlash(s), string(filepath.Separator)+".") {
if strings.HasSuffix(s, string(filepath.Separator)+".") {
if s2 != string(filepath.Separator) {
s2 += string(filepath.Separator)
}
s2 += "."
} else if strings.HasSuffix(filepath.FromSlash(s), string(filepath.Separator)) && s2 != string(filepath.Separator) {
} else if strings.HasSuffix(s, string(filepath.Separator)) && s2 != string(filepath.Separator) {
s2 += string(filepath.Separator)
}
return s2, nil
Expand Down
3 changes: 3 additions & 0 deletions util/system/path.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,9 @@ func ToSlash(inputPath, inputOS string) string {
separator := "/"
if inputOS == "windows" {
separator = "\\"
} else {
// Return early. No point in replacing "/" with "/"
return inputPath
}
return strings.Replace(inputPath, separator, "/", -1)
}
Expand Down

0 comments on commit b829c52

Please sign in to comment.