|
|
@ -17,6 +17,7 @@ |
|
|
|
package cmd |
|
|
|
package cmd |
|
|
|
|
|
|
|
|
|
|
|
import ( |
|
|
|
import ( |
|
|
|
|
|
|
|
"errors" |
|
|
|
"os" |
|
|
|
"os" |
|
|
|
"runtime" |
|
|
|
"runtime" |
|
|
|
"syscall" |
|
|
|
"syscall" |
|
|
@ -24,86 +25,54 @@ import ( |
|
|
|
|
|
|
|
|
|
|
|
// Function not implemented error
|
|
|
|
// Function not implemented error
|
|
|
|
func isSysErrNoSys(err error) bool { |
|
|
|
func isSysErrNoSys(err error) bool { |
|
|
|
if err == syscall.ENOSYS { |
|
|
|
return errors.Is(err, syscall.ENOSYS) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.ENOSYS |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Not supported error
|
|
|
|
// Not supported error
|
|
|
|
func isSysErrOpNotSupported(err error) bool { |
|
|
|
func isSysErrOpNotSupported(err error) bool { |
|
|
|
if err == syscall.EOPNOTSUPP { |
|
|
|
return errors.Is(err, syscall.EOPNOTSUPP) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.EOPNOTSUPP |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// No space left on device error
|
|
|
|
// No space left on device error
|
|
|
|
func isSysErrNoSpace(err error) bool { |
|
|
|
func isSysErrNoSpace(err error) bool { |
|
|
|
if err == syscall.ENOSPC { |
|
|
|
return errors.Is(err, syscall.ENOSPC) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.ENOSPC |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Input/output error
|
|
|
|
// Input/output error
|
|
|
|
func isSysErrIO(err error) bool { |
|
|
|
func isSysErrIO(err error) bool { |
|
|
|
if err == syscall.EIO { |
|
|
|
return errors.Is(err, syscall.EIO) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.EIO |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the given error corresponds to EISDIR (is a directory).
|
|
|
|
// Check if the given error corresponds to EISDIR (is a directory).
|
|
|
|
func isSysErrIsDir(err error) bool { |
|
|
|
func isSysErrIsDir(err error) bool { |
|
|
|
if err == syscall.EISDIR { |
|
|
|
return errors.Is(err, syscall.EISDIR) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.EISDIR |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the given error corresponds to ENOTDIR (is not a directory).
|
|
|
|
// Check if the given error corresponds to ENOTDIR (is not a directory).
|
|
|
|
func isSysErrNotDir(err error) bool { |
|
|
|
func isSysErrNotDir(err error) bool { |
|
|
|
if err == syscall.ENOTDIR { |
|
|
|
return errors.Is(err, syscall.ENOTDIR) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.ENOTDIR |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the given error corresponds to the ENAMETOOLONG (name too long).
|
|
|
|
// Check if the given error corresponds to the ENAMETOOLONG (name too long).
|
|
|
|
func isSysErrTooLong(err error) bool { |
|
|
|
func isSysErrTooLong(err error) bool { |
|
|
|
if err == syscall.ENAMETOOLONG { |
|
|
|
return errors.Is(err, syscall.ENAMETOOLONG) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && pathErr.Err == syscall.ENAMETOOLONG |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if the given error corresponds to ENOTEMPTY for unix
|
|
|
|
// Check if the given error corresponds to ENOTEMPTY for unix
|
|
|
|
// and ERROR_DIR_NOT_EMPTY for windows (directory not empty).
|
|
|
|
// and ERROR_DIR_NOT_EMPTY for windows (directory not empty).
|
|
|
|
func isSysErrNotEmpty(err error) bool { |
|
|
|
func isSysErrNotEmpty(err error) bool { |
|
|
|
if err == syscall.ENOTEMPTY { |
|
|
|
if errors.Is(err, syscall.ENOTEMPTY) { |
|
|
|
return true |
|
|
|
return true |
|
|
|
} |
|
|
|
} |
|
|
|
if pathErr, ok := err.(*os.PathError); ok { |
|
|
|
var pathErr *os.PathError |
|
|
|
|
|
|
|
if errors.As(err, &pathErr) { |
|
|
|
if runtime.GOOS == globalWindowsOSName { |
|
|
|
if runtime.GOOS == globalWindowsOSName { |
|
|
|
if errno, _ok := pathErr.Err.(syscall.Errno); _ok && errno == 0x91 { |
|
|
|
var errno syscall.Errno |
|
|
|
|
|
|
|
if errors.As(pathErr.Err, &errno) { |
|
|
|
// ERROR_DIR_NOT_EMPTY
|
|
|
|
// ERROR_DIR_NOT_EMPTY
|
|
|
|
return true |
|
|
|
return errno == 0x91 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
if pathErr.Err == syscall.ENOTEMPTY { |
|
|
|
|
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
@ -113,10 +82,12 @@ func isSysErrPathNotFound(err error) bool { |
|
|
|
if runtime.GOOS != globalWindowsOSName { |
|
|
|
if runtime.GOOS != globalWindowsOSName { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
if pathErr, ok := err.(*os.PathError); ok { |
|
|
|
var pathErr *os.PathError |
|
|
|
if errno, _ok := pathErr.Err.(syscall.Errno); _ok && errno == 0x03 { |
|
|
|
if errors.As(err, &pathErr) { |
|
|
|
|
|
|
|
var errno syscall.Errno |
|
|
|
|
|
|
|
if errors.As(pathErr.Err, &errno) { |
|
|
|
// ERROR_PATH_NOT_FOUND
|
|
|
|
// ERROR_PATH_NOT_FOUND
|
|
|
|
return true |
|
|
|
return errno == 0x03 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
return false |
|
|
|
return false |
|
|
@ -128,20 +99,22 @@ func isSysErrHandleInvalid(err error) bool { |
|
|
|
return false |
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
// Check if err contains ERROR_INVALID_HANDLE errno
|
|
|
|
// Check if err contains ERROR_INVALID_HANDLE errno
|
|
|
|
errno, ok := err.(syscall.Errno) |
|
|
|
var pathErr *os.PathError |
|
|
|
return ok && errno == 0x6 |
|
|
|
if errors.As(err, &pathErr) { |
|
|
|
|
|
|
|
var errno syscall.Errno |
|
|
|
|
|
|
|
if errors.As(pathErr.Err, &errno) { |
|
|
|
|
|
|
|
// ERROR_PATH_NOT_FOUND
|
|
|
|
|
|
|
|
return errno == 0x6 |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return false |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func isSysErrCrossDevice(err error) bool { |
|
|
|
func isSysErrCrossDevice(err error) bool { |
|
|
|
e, ok := err.(*os.LinkError) |
|
|
|
return errors.Is(err, syscall.EXDEV) |
|
|
|
return ok && e.Err == syscall.EXDEV |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Check if given error corresponds to too many open files
|
|
|
|
// Check if given error corresponds to too many open files
|
|
|
|
func isSysErrTooManyFiles(err error) bool { |
|
|
|
func isSysErrTooManyFiles(err error) bool { |
|
|
|
if err == syscall.ENFILE || err == syscall.EMFILE { |
|
|
|
return errors.Is(err, syscall.ENFILE) || errors.Is(err, syscall.EMFILE) |
|
|
|
return true |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
pathErr, ok := err.(*os.PathError) |
|
|
|
|
|
|
|
return ok && (pathErr.Err == syscall.ENFILE || pathErr.Err == syscall.EMFILE) |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|