瀏覽代碼

Windows: Error if mapping single file volume

Signed-off-by: John Howard <jhoward@microsoft.com>
John Howard 8 年之前
父節點
當前提交
1b62b8c084
共有 2 個文件被更改,包括 19 次插入0 次删除
  1. 1 0
      volume/volume_test.go
  2. 18 0
      volume/volume_windows.go

+ 1 - 0
volume/volume_test.go

@@ -77,6 +77,7 @@ func TestParseMountSpec(t *testing.T) {
 			`lpt7:d:`:                          `cannot be a reserved word for Windows filenames`,
 			`lpt7:d:`:                          `cannot be a reserved word for Windows filenames`,
 			`lpt8:d:`:                          `cannot be a reserved word for Windows filenames`,
 			`lpt8:d:`:                          `cannot be a reserved word for Windows filenames`,
 			`lpt9:d:`:                          `cannot be a reserved word for Windows filenames`,
 			`lpt9:d:`:                          `cannot be a reserved word for Windows filenames`,
+			`c:\windows\system32\ntdll.dll`:    `Only directories can be mapped on this platform`,
 		}
 		}
 
 
 	} else {
 	} else {

+ 18 - 0
volume/volume_windows.go

@@ -177,6 +177,24 @@ func ParseMountSpec(spec string, volumeDriver string) (*MountPoint, error) {
 		}
 		}
 	}
 	}
 
 
+	// Fix #26329. If the destination appears to be a file, and the source is null,
+	// it may be because we've fallen through the possible naming regex and hit a
+	// situation where the user intention was to map a file into a container through
+	// a local volume, but this is not supported by the platform.
+	if len(mp.Source) == 0 && len(mp.Destination) > 0 {
+		var fi os.FileInfo
+		var err error
+		if fi, err = os.Stat(mp.Destination); err == nil {
+			validName, err := IsVolumeNameValid(mp.Destination)
+			if err != nil {
+				return nil, err
+			}
+			if !validName && !fi.IsDir() {
+				return nil, fmt.Errorf("file '%s' cannot be mapped. Only directories can be mapped on this platform", mp.Destination)
+			}
+		}
+	}
+
 	logrus.Debugf("MP: Source '%s', Dest '%s', RW %t, Name '%s', Driver '%s'", mp.Source, mp.Destination, mp.RW, mp.Name, mp.Driver)
 	logrus.Debugf("MP: Source '%s', Dest '%s', RW %t, Name '%s', Driver '%s'", mp.Source, mp.Destination, mp.RW, mp.Name, mp.Driver)
 	return mp, nil
 	return mp, nil
 }
 }