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,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

View File

@ -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
}

View File

@ -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",