Skip to content

Commit f1657ec

Browse files
Fix various nits
Signed-off-by: Gabriel Adrian Samfira <[email protected]>
1 parent 69f2c06 commit f1657ec

File tree

4 files changed

+10
-13
lines changed

4 files changed

+10
-13
lines changed

client/llb/fileop.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
_ "crypto/sha256" // for opencontainers/go-digest
66
"os"
77
"path"
8-
"path/filepath"
98
"strconv"
109
"strings"
1110
"time"
@@ -523,9 +522,7 @@ func (a *fileActionCopy) toProtoAction(ctx context.Context, parent string, base
523522
}
524523

525524
func (a *fileActionCopy) sourcePath(ctx context.Context) (string, error) {
526-
// filepath.Clean() also does a filepath.FromSlash(). Explicitly convert back to UNIX path
527-
// separators.
528-
p := filepath.ToSlash(filepath.Clean(a.src))
525+
p := path.Clean(a.src)
529526
dir := "/"
530527
var err error
531528
if !path.IsAbs(p) {

frontend/dockerfile/dockerfile2llb/convert.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1185,7 +1185,7 @@ func dispatchCopy(d *dispatchState, cfg copyConfig) error {
11851185
}}, copyOpt...)
11861186

11871187
if a == nil {
1188-
a = llb.Copy(st, filepath.ToSlash(f), dest, opts...)
1188+
a = llb.Copy(st, system.ToSlash(f, d.platform.OS), dest, opts...)
11891189
} else {
11901190
a = a.Copy(st, filepath.ToSlash(f), dest, opts...)
11911191
}
@@ -1423,11 +1423,11 @@ func pathRelativeToWorkingDir(s llb.State, p string, platform ocispecs.Platform)
14231423
}
14241424
p, err = system.CheckSystemDriveAndRemoveDriveLetter(p, platform.OS)
14251425
if err != nil {
1426-
return "", errors.Wrap(err, "remving drive letter")
1426+
return "", errors.Wrap(err, "removing drive letter")
14271427
}
14281428

14291429
if system.IsAbs(p, platform.OS) {
1430-
return p, nil
1430+
return system.NormalizePath("/", p, platform.OS, false)
14311431
}
14321432
return system.NormalizePath(dir, p, platform.OS, false)
14331433
}

solver/llbsolver/file/backend.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -352,13 +352,14 @@ func cleanPath(s string) (string, error) {
352352
if err != nil {
353353
return "", errors.Wrap(err, "removing drive letter")
354354
}
355+
s = filepath.FromSlash(s)
355356
s2 := filepath.Join("/", s)
356-
if strings.HasSuffix(filepath.FromSlash(s), string(filepath.Separator)+".") {
357+
if strings.HasSuffix(s, string(filepath.Separator)+".") {
357358
if s2 != string(filepath.Separator) {
358359
s2 += string(filepath.Separator)
359360
}
360361
s2 += "."
361-
} else if strings.HasSuffix(filepath.FromSlash(s), string(filepath.Separator)) && s2 != string(filepath.Separator) {
362+
} else if strings.HasSuffix(s, string(filepath.Separator)) && s2 != string(filepath.Separator) {
362363
s2 += string(filepath.Separator)
363364
}
364365
return s2, nil

util/system/path.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,11 +86,10 @@ func NormalizePath(parent, newPath, inputOS string, keepSlash bool) (string, err
8686
}
8787

8888
func ToSlash(inputPath, inputOS string) string {
89-
separator := "/"
90-
if inputOS == "windows" {
91-
separator = "\\"
89+
if inputOS != "windows" {
90+
return inputPath
9291
}
93-
return strings.Replace(inputPath, separator, "/", -1)
92+
return strings.Replace(inputPath, "\\", "/", -1)
9493
}
9594

9695
func FromSlash(inputPath, inputOS string) string {

0 commit comments

Comments
 (0)