Merge pull request #7344 from thaJeztah/archive_cleanup
archive: replace tarName() with filepath.ToSlash()
This commit is contained in:
commit
1d6d5b4102
@ -574,11 +574,9 @@ func (cw *ChangeWriter) HandleChange(k fs.ChangeKind, p string, f os.FileInfo, e
|
|||||||
return fmt.Errorf("failed to make path relative: %w", err)
|
return fmt.Errorf("failed to make path relative: %w", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
name, err = tarName(name)
|
// Canonicalize to POSIX-style paths using forward slashes. Directory
|
||||||
if err != nil {
|
// entries must end with a slash.
|
||||||
return fmt.Errorf("cannot canonicalize path: %w", err)
|
name = filepath.ToSlash(name)
|
||||||
}
|
|
||||||
// suffix with '/' for directories
|
|
||||||
if f.IsDir() && !strings.HasSuffix(name, "/") {
|
if f.IsDir() && !strings.HasSuffix(name, "/") {
|
||||||
name += "/"
|
name += "/"
|
||||||
}
|
}
|
||||||
|
@ -34,10 +34,6 @@ import (
|
|||||||
"golang.org/x/sys/unix"
|
"golang.org/x/sys/unix"
|
||||||
)
|
)
|
||||||
|
|
||||||
func tarName(p string) (string, error) {
|
|
||||||
return p, nil
|
|
||||||
}
|
|
||||||
|
|
||||||
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
||||||
return perm
|
return perm
|
||||||
}
|
}
|
||||||
|
@ -26,21 +26,6 @@ import (
|
|||||||
"github.com/moby/sys/sequential"
|
"github.com/moby/sys/sequential"
|
||||||
)
|
)
|
||||||
|
|
||||||
// tarName returns platform-specific filepath
|
|
||||||
// to canonical posix-style path for tar archival. p is relative
|
|
||||||
// path.
|
|
||||||
func tarName(p string) (string, error) {
|
|
||||||
// windows: convert windows style relative path with backslashes
|
|
||||||
// into forward slashes. Since windows does not allow '/' or '\'
|
|
||||||
// in file names, it is mostly safe to replace however we must
|
|
||||||
// check just in case
|
|
||||||
if strings.Contains(p, "/") {
|
|
||||||
return "", fmt.Errorf("windows path contains forward slash: %s", p)
|
|
||||||
}
|
|
||||||
|
|
||||||
return strings.Replace(p, string(os.PathSeparator), "/", -1), nil
|
|
||||||
}
|
|
||||||
|
|
||||||
// chmodTarEntry is used to adjust the file permissions used in tar header based
|
// chmodTarEntry is used to adjust the file permissions used in tar header based
|
||||||
// on the platform the archival is done.
|
// on the platform the archival is done.
|
||||||
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
func chmodTarEntry(perm os.FileMode) os.FileMode {
|
||||||
|
Loading…
Reference in New Issue
Block a user