Bladeren bron

Fix for creation of windows source directory in case it didn't exist

Signed-off-by: Ameya Gawde <agawde@mirantis.com>
Ameya Gawde 1 jaar geleden
bovenliggende
commit
e6b06e24fd
3 gewijzigde bestanden met toevoegingen van 17 en 2 verwijderingen
  1. 1 1
      volume/mounts/lcow_parser_test.go
  2. 15 0
      volume/mounts/windows_parser.go
  3. 1 1
      volume/mounts/windows_parser_test.go

+ 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

@@ -10,6 +10,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.
@@ -246,6 +247,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)}
 		}
@@ -336,6 +342,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

@@ -16,6 +16,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`,
@@ -45,7 +46,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`,