Add ismounted check in unmountpath function

This change is for fixing PR #30930. The function should check if the
mountpath is still mounted or not. If it is not, it should continue with
removing the directory instead of returning error.
This commit is contained in:
Jing Xu
2016-08-19 15:24:18 -07:00
parent 7523669699
commit cafd126ecd

View File

@@ -73,14 +73,28 @@ func UnmountPath(mountPath string, mounter mount.Interface) error {
return nil return nil
} }
err := mounter.Unmount(mountPath) notMnt, err := mounter.IsLikelyNotMountPoint(mountPath)
if err == nil { if err != nil {
// Only delete directory on successful unmount return err
glog.V(5).Infof("Unmounted %q. Deleting path.", mountPath) }
if notMnt {
glog.Warningf("Warning: %q is not a mountpoint, deleting", mountPath)
return os.Remove(mountPath) return os.Remove(mountPath)
} }
return err // Unmount the mount path
if err := mounter.Unmount(mountPath); err != nil {
return err
}
notMnt, mntErr := mounter.IsLikelyNotMountPoint(mountPath)
if mntErr != nil {
return err
}
if notMnt {
glog.V(4).Info("%q is unmounted, deleting the directory", mountPath)
return os.Remove(mountPath)
}
return nil
} }
// PathExists returns true if the specified path exists. // PathExists returns true if the specified path exists.