Fix path separator on Windows

On Windows os.PathSeparator is \ but here it's all unix file paths being manipulated.

Signed-off-by: Mathieu Champlon <mathieu.champlon@docker.com>
This commit is contained in:
Mathieu Champlon 2018-09-10 21:53:09 +02:00
parent 576eab21c1
commit 54868329e6
2 changed files with 4 additions and 4 deletions

View File

@ -454,7 +454,7 @@ func filesystem(m Moby, tw *tar.Writer, idMap map[string]uint32) error {
return errors.New("Did not specify path for file") return errors.New("Did not specify path for file")
} }
// tar archives should not have absolute paths // tar archives should not have absolute paths
if f.Path[0] == os.PathSeparator { if f.Path[0] == '/' {
f.Path = f.Path[1:] f.Path = f.Path[1:]
} }
mode := int64(0600) mode := int64(0600)

View File

@ -58,11 +58,11 @@ func tarPrefix(path string, tw tarWriter) error {
if path == "" { if path == "" {
return nil return nil
} }
if path[len(path)-1] != byte('/') { if path[len(path)-1] != '/' {
return fmt.Errorf("path does not end with /: %s", path) return fmt.Errorf("path does not end with /: %s", path)
} }
path = path[:len(path)-1] path = path[:len(path)-1]
if path[0] == byte('/') { if path[0] == '/' {
return fmt.Errorf("path should be relative: %s", path) return fmt.Errorf("path should be relative: %s", path)
} }
mkdir := "" mkdir := ""
@ -85,7 +85,7 @@ func tarPrefix(path string, tw tarWriter) error {
// ImageTar takes a Docker image and outputs it to a tar stream // ImageTar takes a Docker image and outputs it to a tar stream
func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, trust bool, pull bool, resolv string) (e error) { func ImageTar(ref *reference.Spec, prefix string, tw tarWriter, trust bool, pull bool, resolv string) (e error) {
log.Debugf("image tar: %s %s", ref, prefix) log.Debugf("image tar: %s %s", ref, prefix)
if prefix != "" && prefix[len(prefix)-1] != byte('/') { if prefix != "" && prefix[len(prefix)-1] != '/' {
return fmt.Errorf("prefix does not end with /: %s", prefix) return fmt.Errorf("prefix does not end with /: %s", prefix)
} }