Browse code

Do not try to cleanupMounts if daemon.repository is empty

Signed-off-by: Chun Chen <ramichen@tencent.com>

Chun Chen authored on 2015/08/25 16:58:33
Showing 2 changed files
... ...
@@ -24,6 +24,9 @@ func (daemon *Daemon) cleanupMounts() error {
24 24
 }
25 25
 
26 26
 func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
27
+	if daemon.repository == "" {
28
+		return nil
29
+	}
27 30
 	sc := bufio.NewScanner(reader)
28 31
 	var errors []string
29 32
 	for sc.Scan() {
... ...
@@ -56,3 +56,19 @@ func TestCleanupMounts(t *testing.T) {
56 56
 		t.Fatalf("Expected to unmount the mqueue")
57 57
 	}
58 58
 }
59
+
60
+func TestNotCleanupMounts(t *testing.T) {
61
+	d := &Daemon{
62
+		repository: "",
63
+	}
64
+	var unmounted bool
65
+	unmount := func(target string) error {
66
+		unmounted = true
67
+		return nil
68
+	}
69
+	mountInfo := `234 232 0:59 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k`
70
+	d.cleanupMountsFromReader(strings.NewReader(mountInfo), unmount)
71
+	if unmounted {
72
+		t.Fatalf("Expected not to clean up /dev/shm")
73
+	}
74
+}