瀏覽代碼

Fix relative path on windows for uuid paths

Signed-off-by: Tonis Tiigi <tonistiigi@gmail.com>
Tonis Tiigi 8 年之前
父節點
當前提交
684633f734
共有 1 個文件被更改,包括 19 次插入2 次删除
  1. 19 2
      builder/remotecontext/lazycontext.go

+ 19 - 2
builder/remotecontext/lazycontext.go

@@ -5,6 +5,8 @@ import (
 	"io"
 	"io"
 	"os"
 	"os"
 	"path/filepath"
 	"path/filepath"
+	"runtime"
+	"strings"
 
 
 	"github.com/docker/docker/builder"
 	"github.com/docker/docker/builder"
 	"github.com/docker/docker/pkg/pools"
 	"github.com/docker/docker/pkg/pools"
@@ -56,7 +58,7 @@ func (c *lazyContext) Stat(path string) (string, builder.FileInfo, error) {
 		return "", nil, errors.WithStack(convertPathError(err, cleanPath))
 		return "", nil, errors.WithStack(convertPathError(err, cleanPath))
 	}
 	}
 
 
-	relPath, err := filepath.Rel(c.root, fullPath)
+	relPath, err := rel(c.root, fullPath)
 	if err != nil {
 	if err != nil {
 		return "", nil, errors.WithStack(convertPathError(err, cleanPath))
 		return "", nil, errors.WithStack(convertPathError(err, cleanPath))
 	}
 	}
@@ -82,7 +84,7 @@ func (c *lazyContext) Walk(root string, walkFn builder.WalkFunc) error {
 		return err
 		return err
 	}
 	}
 	return filepath.Walk(fullPath, func(fullPath string, fi os.FileInfo, err error) error {
 	return filepath.Walk(fullPath, func(fullPath string, fi os.FileInfo, err error) error {
-		relPath, err := filepath.Rel(c.root, fullPath)
+		relPath, err := rel(c.root, fullPath)
 		if err != nil {
 		if err != nil {
 			return errors.WithStack(err)
 			return errors.WithStack(err)
 		}
 		}
@@ -147,3 +149,18 @@ func convertPathError(err error, cleanpath string) error {
 	}
 	}
 	return err
 	return err
 }
 }
+
+func rel(basepath, targpath string) (string, error) {
+	// filepath.Rel can't handle UUID paths in windows
+	if runtime.GOOS == "windows" {
+		pfx := basepath + `\`
+		if strings.HasPrefix(targpath, pfx) {
+			p := strings.TrimPrefix(targpath, pfx)
+			if p == "" {
+				p = "."
+			}
+			return p, nil
+		}
+	}
+	return filepath.Rel(basepath, targpath)
+}