Browse code

Merge pull request #31265 from cyli/remove_swarm_subdirs

Rather than remove the swarm directory and re-create, remove the subdirs

Brian Goff authored on 2017/03/08 04:30:34
Showing 1 changed files
... ...
@@ -38,12 +38,19 @@ func savePersistentState(root string, config nodeStartConfig) error {
38 38
 
39 39
 func clearPersistentState(root string) error {
40 40
 	// todo: backup this data instead of removing?
41
-	if err := os.RemoveAll(root); err != nil {
41
+	// rather than delete the entire swarm directory, delete the contents in order to preserve the inode
42
+	// (for example, allowing it to be bind-mounted)
43
+	files, err := ioutil.ReadDir(root)
44
+	if err != nil {
42 45
 		return err
43 46
 	}
44
-	if err := os.MkdirAll(root, 0700); err != nil {
45
-		return err
47
+
48
+	for _, f := range files {
49
+		if err := os.RemoveAll(filepath.Join(root, f.Name())); err != nil {
50
+			return err
51
+		}
46 52
 	}
53
+
47 54
 	return nil
48 55
 }
49 56