Check and return error first in IsSymlinkExist and IsBindMountExist

This commit is contained in:
Masaki Kimura 2019-11-04 21:07:48 +00:00
parent 8a159d7253
commit 5a351e3014

View File

@ -231,7 +231,14 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
// On other cases, return false with error from Lstat().
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
fi, err := os.Lstat(mapPath)
if err == nil {
if err != nil {
// If file doesn't exist, return false and no error
if os.IsNotExist(err) {
return false, nil
}
// Return error from Lstat()
return false, err
}
// If file exits and it's symbolic link, return true and no error
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
return true, nil
@ -239,20 +246,21 @@ func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
// If file exits but it's not symbolic link, return fale and no error
return false, nil
}
// If file doesn't exist, return false and no error
if os.IsNotExist(err) {
return false, nil
}
// Return error from Lstat()
return false, err
}
// IsBindMountExist returns true if specified file exists and the type is device.
// If file doesn't exist, or file exists but not device, return false with no error.
// On other cases, return false with error from Lstat().
func (v VolumePathHandler) IsBindMountExist(mapPath string) (bool, error) {
fi, err := os.Lstat(mapPath)
if err == nil {
if err != nil {
// If file doesn't exist, return false and no error
if os.IsNotExist(err) {
return false, nil
}
// Return error from Lstat()
return false, err
}
// If file exits and it's device, return true and no error
if fi.Mode()&os.ModeDevice == os.ModeDevice {
return true, nil
@ -260,13 +268,6 @@ func (v VolumePathHandler) IsBindMountExist(mapPath string) (bool, error) {
// If file exits but it's not device, return fale and no error
return false, nil
}
// If file doesn't exist, return false and no error
if os.IsNotExist(err) {
return false, nil
}
// Return error from Lstat()
return false, err
}
// GetDeviceBindMountRefs searches bind mounts under global map path
func (v VolumePathHandler) GetDeviceBindMountRefs(devPath string, mapPath string) ([]string, error) {