Skip to content

Commit d597584

Browse files
committed
pkg/archive: make CanonicalTarNameForPath and alias for filepath.ToSlash
filepath.ToSlash is already a no-op on non-Windows platforms, so there's no need to provide multiple implementations. We could consider deprecating this function, but it's used in the CLI, and perhaps it's still useful to have a canonical location to perform this normalization. Signed-off-by: Sebastiaan van Stijn <[email protected]>
1 parent 18bb8fe commit d597584

3 files changed

Lines changed: 9 additions & 17 deletions

File tree

pkg/archive/archive.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,10 +555,17 @@ func newTarAppender(idMapping idtools.IdentityMapping, writer io.Writer, chownOp
555555
}
556556
}
557557

558-
// canonicalTarName provides a platform-independent and consistent posix-style
558+
// CanonicalTarNameForPath canonicalizes relativePath to a POSIX-style path using
559+
// forward slashes. It is an alias for filepath.ToSlash, which is a no-op on
560+
// Linux and Unix.
561+
func CanonicalTarNameForPath(relativePath string) string {
562+
return filepath.ToSlash(relativePath)
563+
}
564+
565+
// canonicalTarName provides a platform-independent and consistent POSIX-style
559566
// path for files and directories to be archived regardless of the platform.
560567
func canonicalTarName(name string, isDir bool) string {
561-
name = CanonicalTarNameForPath(name)
568+
name = filepath.ToSlash(name)
562569

563570
// suffix with '/' for directories
564571
if isDir && !strings.HasSuffix(name, "/") {

pkg/archive/archive_unix.go

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,8 @@ func getWalkRoot(srcPath string, include string) string {
3535
return strings.TrimSuffix(srcPath, string(filepath.Separator)) + string(filepath.Separator) + include
3636
}
3737

38-
// CanonicalTarNameForPath returns platform-specific filepath
39-
// to canonical posix-style path for tar archival. p is relative
40-
// path.
41-
func CanonicalTarNameForPath(p string) string {
42-
return p // already unix-style
43-
}
44-
4538
// chmodTarEntry is used to adjust the file permissions used in tar header based
4639
// on the platform the archival is done.
47-
4840
func chmodTarEntry(perm os.FileMode) os.FileMode {
4941
return perm // noop for unix as golang APIs provide perm bits correctly
5042
}

pkg/archive/archive_windows.go

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,6 @@ func getWalkRoot(srcPath string, include string) string {
2121
return filepath.Join(srcPath, include)
2222
}
2323

24-
// CanonicalTarNameForPath returns platform-specific filepath
25-
// to canonical posix-style path for tar archival. p is relative
26-
// path.
27-
func CanonicalTarNameForPath(p string) string {
28-
return filepath.ToSlash(p)
29-
}
30-
3124
// chmodTarEntry is used to adjust the file permissions used in tar header based
3225
// on the platform the archival is done.
3326
func chmodTarEntry(perm os.FileMode) os.FileMode {

0 commit comments

Comments
 (0)