Procházet zdrojové kódy

Merge pull request #10243 from cpuguy83/10242_fix_stat_on_err

Fix call to nil stat
Michael Crosby před 10 roky
rodič
revize
12dd9af951
2 změnil soubory, kde provedl 8 přidání a 20 odebrání
  1. 2 0
      daemon/start.go
  2. 6 20
      volumes/volume.go

+ 2 - 0
daemon/start.go

@@ -53,6 +53,8 @@ func (daemon *Daemon) setHostConfig(container *Container, hostConfig *runconfig.
 	if err := parseSecurityOpt(container, hostConfig); err != nil {
 	if err := parseSecurityOpt(container, hostConfig); err != nil {
 		return err
 		return err
 	}
 	}
+
+	// FIXME: this should be handled by the volume subsystem
 	// Validate the HostConfig binds. Make sure that:
 	// Validate the HostConfig binds. Make sure that:
 	// the source exists
 	// the source exists
 	for _, bind := range hostConfig.Binds {
 	for _, bind := range hostConfig.Binds {

+ 6 - 20
volumes/volume.go

@@ -86,30 +86,14 @@ func (v *Volume) AddContainer(containerId string) {
 	v.lock.Unlock()
 	v.lock.Unlock()
 }
 }
 
 
-func (v *Volume) createIfNotExist() error {
-	if stat, err := os.Stat(v.Path); err != nil && os.IsNotExist(err) {
-		if stat.IsDir() {
-			os.MkdirAll(v.Path, 0755)
-		}
-
-		if err := os.MkdirAll(filepath.Dir(v.Path), 0755); err != nil {
-			return err
-		}
-		f, err := os.OpenFile(v.Path, os.O_CREATE, 0755)
-		if err != nil {
-			return err
-		}
-		f.Close()
-	}
-	return nil
-}
-
 func (v *Volume) initialize() error {
 func (v *Volume) initialize() error {
 	v.lock.Lock()
 	v.lock.Lock()
 	defer v.lock.Unlock()
 	defer v.lock.Unlock()
 
 
-	if err := v.createIfNotExist(); err != nil {
-		return err
+	if _, err := os.Stat(v.Path); err != nil && os.IsNotExist(err) {
+		if err := os.MkdirAll(v.Path, 0755); err != nil {
+			return err
+		}
 	}
 	}
 
 
 	if err := os.MkdirAll(v.configPath, 0755); err != nil {
 	if err := os.MkdirAll(v.configPath, 0755); err != nil {
@@ -133,6 +117,7 @@ func (v *Volume) ToDisk() error {
 	defer v.lock.Unlock()
 	defer v.lock.Unlock()
 	return v.toDisk()
 	return v.toDisk()
 }
 }
+
 func (v *Volume) toDisk() error {
 func (v *Volume) toDisk() error {
 	data, err := json.Marshal(v)
 	data, err := json.Marshal(v)
 	if err != nil {
 	if err != nil {
@@ -146,6 +131,7 @@ func (v *Volume) toDisk() error {
 
 
 	return ioutil.WriteFile(pth, data, 0666)
 	return ioutil.WriteFile(pth, data, 0666)
 }
 }
+
 func (v *Volume) FromDisk() error {
 func (v *Volume) FromDisk() error {
 	v.lock.Lock()
 	v.lock.Lock()
 	defer v.lock.Unlock()
 	defer v.lock.Unlock()