mirror of
https://github.com/rclone/rclone.git
synced 2024-11-22 10:23:16 +08:00
vfs: use os package errors where possible
This commit is contained in:
parent
c1aaff220d
commit
1a8f824bad
|
@ -632,24 +632,21 @@ func translateError(err error) (errc int) {
|
|||
if err == nil {
|
||||
return 0
|
||||
}
|
||||
cause := errors.Cause(err)
|
||||
if mErr, ok := cause.(vfs.Error); ok {
|
||||
switch mErr {
|
||||
case vfs.OK:
|
||||
return 0
|
||||
case vfs.ENOENT:
|
||||
return -fuse.ENOENT
|
||||
case vfs.ENOTEMPTY:
|
||||
return -fuse.ENOTEMPTY
|
||||
case vfs.EEXIST:
|
||||
return -fuse.EEXIST
|
||||
case vfs.ESPIPE:
|
||||
return -fuse.ESPIPE
|
||||
case vfs.EBADF:
|
||||
return -fuse.EBADF
|
||||
case vfs.EROFS:
|
||||
return -fuse.EROFS
|
||||
}
|
||||
switch errors.Cause(err) {
|
||||
case vfs.OK:
|
||||
return 0
|
||||
case vfs.ENOENT:
|
||||
return -fuse.ENOENT
|
||||
case vfs.ENOTEMPTY:
|
||||
return -fuse.ENOTEMPTY
|
||||
case vfs.EEXIST:
|
||||
return -fuse.EEXIST
|
||||
case vfs.ESPIPE:
|
||||
return -fuse.ESPIPE
|
||||
case vfs.EBADF:
|
||||
return -fuse.EBADF
|
||||
case vfs.EROFS:
|
||||
return -fuse.EROFS
|
||||
}
|
||||
fs.Errorf(nil, "IO error: %v", err)
|
||||
return -fuse.EIO
|
||||
|
|
|
@ -68,24 +68,21 @@ func translateError(err error) error {
|
|||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
cause := errors.Cause(err)
|
||||
if mErr, ok := cause.(vfs.Error); ok {
|
||||
switch mErr {
|
||||
case vfs.OK:
|
||||
return nil
|
||||
case vfs.ENOENT:
|
||||
return fuse.ENOENT
|
||||
case vfs.ENOTEMPTY:
|
||||
return fuse.Errno(syscall.ENOTEMPTY)
|
||||
case vfs.EEXIST:
|
||||
return fuse.EEXIST
|
||||
case vfs.ESPIPE:
|
||||
return fuse.Errno(syscall.ESPIPE)
|
||||
case vfs.EBADF:
|
||||
return fuse.Errno(syscall.EBADF)
|
||||
case vfs.EROFS:
|
||||
return fuse.Errno(syscall.EROFS)
|
||||
}
|
||||
switch errors.Cause(err) {
|
||||
case vfs.OK:
|
||||
return nil
|
||||
case vfs.ENOENT:
|
||||
return fuse.ENOENT
|
||||
case vfs.ENOTEMPTY:
|
||||
return fuse.Errno(syscall.ENOTEMPTY)
|
||||
case vfs.EEXIST:
|
||||
return fuse.EEXIST
|
||||
case vfs.ESPIPE:
|
||||
return fuse.Errno(syscall.ESPIPE)
|
||||
case vfs.EBADF:
|
||||
return fuse.Errno(syscall.EBADF)
|
||||
case vfs.EROFS:
|
||||
return fuse.Errno(syscall.EROFS)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -2,29 +2,34 @@
|
|||
|
||||
package vfs
|
||||
|
||||
import "fmt"
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
)
|
||||
|
||||
// Error describes low level errors in a cross platform way
|
||||
type Error byte
|
||||
|
||||
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go, cmd/serve/webdav/webdav.go
|
||||
// NB if changing errors translateError in cmd/mount/fs.go, cmd/cmount/fs.go
|
||||
|
||||
// Low level errors
|
||||
const (
|
||||
OK Error = iota
|
||||
ENOENT
|
||||
ENOTEMPTY
|
||||
EEXIST
|
||||
ESPIPE
|
||||
EBADF
|
||||
EROFS
|
||||
)
|
||||
|
||||
// Errors which have exact counterparts in os
|
||||
var (
|
||||
ENOENT = os.ErrNotExist
|
||||
EEXIST = os.ErrExist
|
||||
)
|
||||
|
||||
var errorNames = []string{
|
||||
OK: "Success",
|
||||
ENOENT: "No such file or directory",
|
||||
ENOTEMPTY: "Directory not empty",
|
||||
EEXIST: "File exists",
|
||||
ESPIPE: "Illegal seek",
|
||||
EBADF: "Bad file descriptor",
|
||||
EROFS: "Read only file system",
|
||||
|
|
Loading…
Reference in New Issue
Block a user