Ver código fonte

Fix state persistence, create folder if it doesn't exist

JDierkse 3 anos atrás
pai
commit
d8f25cbba6
1 arquivos alterados com 17 adições e 1 exclusões
  1. 17 1
      driver.go

+ 17 - 1
driver.go

@@ -54,9 +54,23 @@ func newiscsiDriver(root string) (*iscsiDriver, error) {
 		return nil, util.LogError("%v already exist and it's not a directory", root)
 	}
 
+	stateFolder := filepath.Join(root, "plugins", "docker-iscsi")
+	fi, err = os.Lstat(stateFolder)
+	if os.IsNotExist(err) {
+		if err := os.MkdirAll(stateFolder, 0755); err != nil {
+			return nil, err
+		}
+	} else if err != nil {
+		return nil, err
+	}
+
+	if fi != nil && !fi.IsDir() {
+		return nil, util.LogError("%v already exist and it's not a directory", stateFolder)
+	}
+
 	d := &iscsiDriver{
 		root:      filepath.Join(root, "volumes"),
-		statePath: filepath.Join(root, "plugins", "docker-iscsi", "iscsi-state.json"),
+		statePath: filepath.Join(stateFolder, "iscsi-state.json"),
 		volumes:   map[string]*iscsiVolume{},
 	}
 
@@ -133,8 +147,10 @@ func (d *iscsiDriver) Remove(r *volume.RemoveRequest) error {
 	if err := os.RemoveAll(v.Mountpoint); err != nil {
 		return util.LogError(err.Error())
 	}
+
 	delete(d.volumes, r.Name)
 	d.saveState()
+
 	return nil
 }