fix issue 4239

pull/4393/head
fenglixa 2019-05-31 10:27:02 +08:00
parent 4e3b9c8907
commit 12b350b518
1 changed files with 6 additions and 3 deletions

View File

@ -132,12 +132,15 @@ func mntCmd(source string, target string, c *MountConfig) string {
// umountCmd returns a command for unmounting
func umountCmd(target string, force bool) string {
flag := ""
// Call fuser before unmount, for killing the processes using the mount point. Notes: don't use 'lsof' to avoid the innocents
flag1 := fmt.Sprintf("sudo fuser -km %s;", target)
flag2 := ""
if force {
flag = "-f "
flag1 = ""
flag2 = "-f "
}
// grep because findmnt will also display the parent!
return fmt.Sprintf("findmnt -T %s | grep %s && sudo umount %s%s || true", target, target, flag, target)
return fmt.Sprintf("[ \"x$(findmnt -T %s | grep %s)\" != \"x\" ] && { %s sudo umount %s%s; } || echo ", target, target, flag1, flag2, target)
}
// Unmount unmounts a path