Do not try to cleanupMounts if daemon.repository is empty

Signed-off-by: Chun Chen <ramichen@tencent.com>
This commit is contained in:
Chun Chen 2015-08-25 15:58:33 +08:00
parent d6e7350b96
commit 213a0f9d86
2 changed files with 19 additions and 0 deletions

View file

@ -24,6 +24,9 @@ func (daemon *Daemon) cleanupMounts() error {
}
func (daemon *Daemon) cleanupMountsFromReader(reader io.Reader, unmount func(target string) error) error {
if daemon.repository == "" {
return nil
}
sc := bufio.NewScanner(reader)
var errors []string
for sc.Scan() {

View file

@ -56,3 +56,19 @@ func TestCleanupMounts(t *testing.T) {
t.Fatalf("Expected to unmount the mqueue")
}
}
func TestNotCleanupMounts(t *testing.T) {
d := &Daemon{
repository: "",
}
var unmounted bool
unmount := func(target string) error {
unmounted = true
return nil
}
mountInfo := `234 232 0:59 / /dev/shm rw,nosuid,nodev,noexec,relatime - tmpfs shm rw,size=65536k`
d.cleanupMountsFromReader(strings.NewReader(mountInfo), unmount)
if unmounted {
t.Fatalf("Expected not to clean up /dev/shm")
}
}