From 1a8f824bad99780eb30685f767d520b3c960ec32 Mon Sep 17 00:00:00 2001 From: Nick Craig-Wood Date: Sat, 28 Oct 2017 20:16:03 +0100 Subject: [PATCH] vfs: use os package errors where possible --- cmd/cmount/fs.go | 33 +++++++++++++++------------------ cmd/mount/fs.go | 33 +++++++++++++++------------------ vfs/errors.go | 17 +++++++++++------ 3 files changed, 41 insertions(+), 42 deletions(-) diff --git a/cmd/cmount/fs.go b/cmd/cmount/fs.go index 1817a01ac..1f1afc486 100644 --- a/cmd/cmount/fs.go +++ b/cmd/cmount/fs.go @@ -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 diff --git a/cmd/mount/fs.go b/cmd/mount/fs.go index 1a470470d..e2520d1be 100644 --- a/cmd/mount/fs.go +++ b/cmd/mount/fs.go @@ -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 } diff --git a/vfs/errors.go b/vfs/errors.go index 483fe9cbc..09a3d74f8 100644 --- a/vfs/errors.go +++ b/vfs/errors.go @@ -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",