Browse Source

pkg/archive: keep walkRoot clean if source is /

Previously, getWalkRoot("/", "foo") would return "//foo"
Now it returns "/foo"

Signed-off-by: Tibor Vass <tibor@docker.com>
(cherry picked from commit 7410f1a859063d4ed3d8fca44f27bdde4c2cb5a3)
Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
Tibor Vass 6 years ago
parent
commit
8677bbe3f3
1 changed files with 2 additions and 1 deletions
  1. 2 1
      pkg/archive/archive_unix.go

+ 2 - 1
pkg/archive/archive_unix.go

@@ -7,6 +7,7 @@ import (
 	"errors"
 	"errors"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
+	"strings"
 	"syscall"
 	"syscall"
 
 
 	"github.com/docker/docker/pkg/idtools"
 	"github.com/docker/docker/pkg/idtools"
@@ -26,7 +27,7 @@ func fixVolumePathPrefix(srcPath string) string {
 // can't use filepath.Join(srcPath,include) because this will clean away
 // can't use filepath.Join(srcPath,include) because this will clean away
 // a trailing "." or "/" which may be important.
 // a trailing "." or "/" which may be important.
 func getWalkRoot(srcPath string, include string) string {
 func getWalkRoot(srcPath string, include string) string {
-	return srcPath + string(filepath.Separator) + include
+	return strings.TrimSuffix(srcPath, string(filepath.Separator)) + string(filepath.Separator) + include
 }
 }
 
 
 // CanonicalTarNameForPath returns platform-specific filepath
 // CanonicalTarNameForPath returns platform-specific filepath