mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-30 06:54:01 +00:00
Check and return error first in IsSymlinkExist and IsBindMountExist
This commit is contained in:
parent
8a159d7253
commit
5a351e3014
@ -231,20 +231,20 @@ func (v VolumePathHandler) RemoveMapPath(mapPath string) error {
|
|||||||
// On other cases, return false with error from Lstat().
|
// On other cases, return false with error from Lstat().
|
||||||
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
||||||
fi, err := os.Lstat(mapPath)
|
fi, err := os.Lstat(mapPath)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
// If file exits and it's symbolic link, return true and no error
|
// If file doesn't exist, return false and no error
|
||||||
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
if os.IsNotExist(err) {
|
||||||
return true, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
// If file exits but it's not symbolic link, return fale and no error
|
// Return error from Lstat()
|
||||||
return false, nil
|
return false, err
|
||||||
}
|
}
|
||||||
// If file doesn't exist, return false and no error
|
// If file exits and it's symbolic link, return true and no error
|
||||||
if os.IsNotExist(err) {
|
if fi.Mode()&os.ModeSymlink == os.ModeSymlink {
|
||||||
return false, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
// Return error from Lstat()
|
// If file exits but it's not symbolic link, return fale and no error
|
||||||
return false, err
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsBindMountExist returns true if specified file exists and the type is device.
|
// IsBindMountExist returns true if specified file exists and the type is device.
|
||||||
@ -252,20 +252,21 @@ func (v VolumePathHandler) IsSymlinkExist(mapPath string) (bool, error) {
|
|||||||
// On other cases, return false with error from Lstat().
|
// On other cases, return false with error from Lstat().
|
||||||
func (v VolumePathHandler) IsBindMountExist(mapPath string) (bool, error) {
|
func (v VolumePathHandler) IsBindMountExist(mapPath string) (bool, error) {
|
||||||
fi, err := os.Lstat(mapPath)
|
fi, err := os.Lstat(mapPath)
|
||||||
if err == nil {
|
if err != nil {
|
||||||
// If file exits and it's device, return true and no error
|
// If file doesn't exist, return false and no error
|
||||||
if fi.Mode()&os.ModeDevice == os.ModeDevice {
|
if os.IsNotExist(err) {
|
||||||
return true, nil
|
return false, nil
|
||||||
}
|
}
|
||||||
// If file exits but it's not device, return fale and no error
|
|
||||||
return false, nil
|
// Return error from Lstat()
|
||||||
|
return false, err
|
||||||
}
|
}
|
||||||
// If file doesn't exist, return false and no error
|
// If file exits and it's device, return true and no error
|
||||||
if os.IsNotExist(err) {
|
if fi.Mode()&os.ModeDevice == os.ModeDevice {
|
||||||
return false, nil
|
return true, nil
|
||||||
}
|
}
|
||||||
// Return error from Lstat()
|
// If file exits but it's not device, return fale and no error
|
||||||
return false, err
|
return false, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// GetDeviceBindMountRefs searches bind mounts under global map path
|
// GetDeviceBindMountRefs searches bind mounts under global map path
|
||||||
|
Loading…
Reference in New Issue
Block a user