-
Notifications
You must be signed in to change notification settings - Fork 305
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
cmd/upspinfs: use the new errors package
I also took out a lot of redundant debugging. Now that I can turn on the fuse libaries debugging a lot of what I had was redundant. Change-Id: I3aa6867da8acd272816736bcb36b347c300da01d Reviewed-on: https://upspin-review.git.corp.google.com/2314 Reviewed-by: Eduardo Pinheiro <edpin@google.com> Reviewed-by: Rob Pike <r@google.com>
- Loading branch information
Showing
5 changed files
with
201 additions
and
192 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
// Copyright 2016 The Upspin Authors. All rights reserved. | ||
// Use of this source code is governed by a BSD-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build darwin linux freebsd netbsd openbsd | ||
|
||
package main | ||
|
||
import ( | ||
"strings" | ||
"syscall" | ||
|
||
"bazil.org/fuse" | ||
|
||
"upspin.io/errors" | ||
"upspin.io/log" | ||
) | ||
|
||
// errnoError is a go string with a POSIX syscall error number. | ||
type errnoError struct { | ||
errno syscall.Errno | ||
err error | ||
} | ||
|
||
func (u *errnoError) Error() string { | ||
return u.err.Error() | ||
} | ||
|
||
func (u *errnoError) Errno() fuse.Errno { | ||
return fuse.Errno(u.errno) | ||
} | ||
|
||
var errs = []struct { | ||
str string | ||
errno syscall.Errno | ||
}{ | ||
{"not found", syscall.ENOENT}, | ||
{"not a directory", syscall.ENOTDIR}, | ||
{"no such", syscall.ENOENT}, | ||
{"permission", syscall.EPERM}, | ||
{"not empty", syscall.ENOTEMPTY}, | ||
} | ||
|
||
var errnoToKind = map[syscall.Errno]errors.Kind{ | ||
syscall.EPERM: errors.Permission, | ||
syscall.EEXIST: errors.Exist, | ||
syscall.ENOENT: errors.NotExist, | ||
syscall.EISDIR: errors.NotFile, | ||
syscall.ENOTDIR: errors.NotDir, | ||
syscall.ENOTEMPTY: errors.NotEmpty, | ||
} | ||
|
||
var kindToErrno = map[errors.Kind]syscall.Errno{ | ||
errors.Permission: syscall.EPERM, | ||
errors.Exist: syscall.EEXIST, | ||
errors.NotExist: syscall.ENOENT, | ||
errors.NotFile: syscall.EISDIR, | ||
errors.NotDir: syscall.ENOTDIR, | ||
errors.NotEmpty: syscall.ENOTEMPTY, | ||
errors.Syntax: syscall.ENOENT, | ||
} | ||
|
||
// e2e converts an upspin error into a fuse one. | ||
func e2e(err error) *errnoError { | ||
errno := syscall.EIO | ||
if ue, ok := err.(*errors.Error); ok { | ||
if e, ok := kindToErrno[ue.Kind]; ok { | ||
errno = e | ||
} | ||
} else { | ||
for _, e := range errs { | ||
if strings.Contains(err.Error(), e.str) { | ||
errno = e.errno | ||
break | ||
} | ||
} | ||
} | ||
log.Debug.Println(err.Error()) | ||
return &errnoError{errno, err} | ||
} | ||
|
||
// classify returns the Kind of error whether or not this is from the upspin errors pkg. | ||
func classify(err error) errors.Kind { | ||
if ue, ok := err.(*errors.Error); ok { | ||
return ue.Kind | ||
} | ||
for _, e := range errs { | ||
if strings.Contains(err.Error(), e.str) { | ||
if k, ok := errnoToKind[e.errno]; ok { | ||
return k | ||
} | ||
break | ||
} | ||
} | ||
return errors.IO | ||
} |
Oops, something went wrong.