Selaa lähdekoodia

Merge 3f2620f5b1d3f43c00acf31571067384d77772ef into b7c059886c0898436db90b4615a27cfb4d93ce34

Ameya Gawde 1 vuosi sitten
vanhempi
commit
67ef35ef8d

+ 4 - 0
pkg/system/filesys.go

@@ -6,6 +6,10 @@ import (
 	"strings"
 )
 
+// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System.
+// For non-Windows machine, it holds no meaning.
+const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
+
 // IsAbs is a platform-agnostic wrapper for filepath.IsAbs.
 //
 // On Windows, golang filepath.IsAbs does not consider a path \windows\system32

+ 0 - 3
pkg/system/filesys_windows.go

@@ -9,9 +9,6 @@ import (
 	"golang.org/x/sys/windows"
 )
 
-// SddlAdministratorsLocalSystem is local administrators plus NT AUTHORITY\System.
-const SddlAdministratorsLocalSystem = "D:P(A;OICI;GA;;;BA)(A;OICI;GA;;;SY)"
-
 // volumePath is a regular expression to check if a path is a Windows
 // volume path (e.g., "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}"
 // or "\\?\Volume{4c1b02c1-d990-11dc-99ae-806e6f6e6963}\").

+ 1 - 1
volume/mounts/lcow_parser_test.go

@@ -15,6 +15,7 @@ func TestLCOWParseMountRaw(t *testing.T) {
 		`/foo/`,
 		`/foo bar`,
 		`c:\:/foo`,
+		`c:\notexist:/foo`,
 		`c:\windows\:/foo`,
 		`c:\windows:/s p a c e`,
 		`c:\windows:/s p a c e:RW`,
@@ -40,7 +41,6 @@ func TestLCOWParseMountRaw(t *testing.T) {
 		`c:\:/foo:xyzzy`:                     "invalid volume specification: ",
 		`/`:                                  "destination can't be '/'",
 		`/..`:                                "destination can't be '/'",
-		`c:\notexist:/foo`:                   `source path does not exist: c:\notexist`,
 		`c:\windows\system32\ntdll.dll:/foo`: `source path must be a directory`,
 		`name<:/foo`:                         `invalid volume specification`,
 		`name>:/foo`:                         `invalid volume specification`,

+ 15 - 0
volume/mounts/windows_parser.go

@@ -11,6 +11,7 @@ import (
 
 	"github.com/docker/docker/api/types/mount"
 	"github.com/docker/docker/pkg/stringid"
+	"github.com/docker/docker/pkg/system"
 )
 
 // NewWindowsParser creates a parser with Windows semantics.
@@ -247,6 +248,11 @@ func (p *windowsParser) validateMountConfigReg(mnt *mount.Mount, additionalValid
 		if err != nil {
 			return &errMountConfig{mnt, err}
 		}
+
+		if windowsDetectMountType(mnt.Target) == mount.TypeNamedPipe {
+			return &errMountConfig{mnt, fmt.Errorf("'%s' is not a valid bind path", mnt.Target)}
+		}
+
 		if !exists {
 			return &errMountConfig{mnt, errBindSourceDoesNotExist(mnt.Source)}
 		}
@@ -349,6 +355,15 @@ func (p *windowsParser) parseMount(arr []string, raw, volumeDriver string, conve
 	spec.Type = windowsDetectMountType(spec.Source)
 	spec.ReadOnly = !p.ReadWrite(mode)
 
+	// We need to create source directory if it didn't exist for short hand bind mounts.
+	if spec.Type == mount.TypeBind {
+		if _, err := os.Stat(spec.Source); os.IsNotExist(err) {
+			if err := system.MkdirAllWithACL(spec.Source, 0, system.SddlAdministratorsLocalSystem); err != nil {
+				return nil, fmt.Errorf("failed to mkdir bind source path: %s", spec.Source)
+			}
+		}
+	}
+
 	// cannot assume that if a volume driver is passed in that we should set it
 	if volumeDriver != "" && spec.Type == mount.TypeVolume {
 		spec.VolumeOptions = &mount.VolumeOptions{

+ 1 - 1
volume/mounts/windows_parser_test.go

@@ -17,6 +17,7 @@ func TestWindowsParseMountRaw(t *testing.T) {
 		`d:\path`,
 		`d:\path with space`,
 		`c:\:d:\`,
+		`c:\notexist:d:`,
 		`c:\windows\:d:`,
 		`c:\windows:d:\s p a c e`,
 		`c:\windows:d:\s p a c e:RW`,
@@ -46,7 +47,6 @@ func TestWindowsParseMountRaw(t *testing.T) {
 		`c:\:d:\:xyzzy`:                    "invalid volume specification: ",
 		`c:`:                               "cannot be `c:`",
 		`c:\`:                              "cannot be `c:`",
-		`c:\notexist:d:`:                   `source path does not exist: c:\notexist`,
 		`c:\windows\system32\ntdll.dll:d:`: `source path must be a directory`,
 		`name<:d:`:                         `invalid volume specification`,
 		`name>:d:`:                         `invalid volume specification`,