Do not try to cleanupMounts if daemon.repository is empty

Signed-off-by: Chun Chen <ramichen@tencent.com>
Upstream-commit: 213a0f9d868db07094f90afa944bd0103f40f629
Component: engine
This commit is contained in:
Chun Chen
2015-08-25 15:58:33 +08:00
parent 1bdb03b312
commit ea3c3f33bf
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")
}
}