vfs: use os package errors where possible

This commit is contained in:
Nick Craig-Wood 2017-10-28 20:16:03 +01:00
parent c1aaff220d
commit 1a8f824bad
3 changed files with 41 additions and 42 deletions

View file

@ -632,9 +632,7 @@ func translateError(err error) (errc int) {
if err == nil { if err == nil {
return 0 return 0
} }
cause := errors.Cause(err) switch errors.Cause(err) {
if mErr, ok := cause.(vfs.Error); ok {
switch mErr {
case vfs.OK: case vfs.OK:
return 0 return 0
case vfs.ENOENT: case vfs.ENOENT:
@ -650,7 +648,6 @@ func translateError(err error) (errc int) {
case vfs.EROFS: case vfs.EROFS:
return -fuse.EROFS return -fuse.EROFS
} }
}
fs.Errorf(nil, "IO error: %v", err) fs.Errorf(nil, "IO error: %v", err)
return -fuse.EIO return -fuse.EIO
} }

View file

@ -68,9 +68,7 @@ func translateError(err error) error {
if err == nil { if err == nil {
return nil return nil
} }
cause := errors.Cause(err) switch errors.Cause(err) {
if mErr, ok := cause.(vfs.Error); ok {
switch mErr {
case vfs.OK: case vfs.OK:
return nil return nil
case vfs.ENOENT: case vfs.ENOENT:
@ -86,6 +84,5 @@ func translateError(err error) error {
case vfs.EROFS: case vfs.EROFS:
return fuse.Errno(syscall.EROFS) return fuse.Errno(syscall.EROFS)
} }
}
return err return err
} }

View file

@ -2,29 +2,34 @@
package vfs package vfs
import "fmt" import (
"fmt"
"os"
)
// Error describes low level errors in a cross platform way // Error describes low level errors in a cross platform way
type Error byte 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 // Low level errors
const ( const (
OK Error = iota OK Error = iota
ENOENT
ENOTEMPTY ENOTEMPTY
EEXIST
ESPIPE ESPIPE
EBADF EBADF
EROFS EROFS
) )
// Errors which have exact counterparts in os
var (
ENOENT = os.ErrNotExist
EEXIST = os.ErrExist
)
var errorNames = []string{ var errorNames = []string{
OK: "Success", OK: "Success",
ENOENT: "No such file or directory",
ENOTEMPTY: "Directory not empty", ENOTEMPTY: "Directory not empty",
EEXIST: "File exists",
ESPIPE: "Illegal seek", ESPIPE: "Illegal seek",
EBADF: "Bad file descriptor", EBADF: "Bad file descriptor",
EROFS: "Read only file system", EROFS: "Read only file system",