github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/errors.go (about) 1 // Copyright 2017 Keybase Inc. All rights reserved. 2 // Use of this source code is governed by a BSD 3 // license that can be found in the LICENSE file. 4 // 5 //go:build !windows 6 // +build !windows 7 8 package libfuse 9 10 import ( 11 "os" 12 "syscall" 13 14 "github.com/pkg/errors" 15 16 "bazil.org/fuse" 17 "github.com/keybase/client/go/kbfs/data" 18 "github.com/keybase/client/go/kbfs/idutil" 19 "github.com/keybase/client/go/kbfs/kbfsblock" 20 "github.com/keybase/client/go/kbfs/kbfsmd" 21 "github.com/keybase/client/go/kbfs/libkbfs" 22 "github.com/keybase/client/go/kbfs/tlfhandle" 23 ) 24 25 type errorWithErrno struct { 26 error 27 errno syscall.Errno 28 } 29 30 var _ fuse.ErrorNumber = errorWithErrno{} 31 32 func (e errorWithErrno) Errno() fuse.Errno { 33 return fuse.Errno(e.errno) 34 } 35 36 func filterError(err error) error { 37 switch errors.Cause(err).(type) { 38 case kbfsblock.ServerErrorUnauthorized: 39 return errorWithErrno{err, syscall.EACCES} 40 41 case kbfsmd.ServerErrorUnauthorized: 42 return errorWithErrno{err, syscall.EACCES} 43 case kbfsmd.ServerErrorWriteAccess: 44 return errorWithErrno{err, syscall.EACCES} 45 case kbfsmd.MetadataIsFinalError: 46 return errorWithErrno{err, syscall.EACCES} 47 48 case idutil.NoSuchUserError: 49 return errorWithErrno{err, syscall.ENOENT} 50 case idutil.NoSuchTeamError: 51 return errorWithErrno{err, syscall.ENOENT} 52 case libkbfs.DirNotEmptyError: 53 return errorWithErrno{err, syscall.ENOTEMPTY} 54 case tlfhandle.ReadAccessError: 55 return errorWithErrno{err, syscall.EACCES} 56 case tlfhandle.WriteAccessError: 57 return errorWithErrno{err, syscall.EACCES} 58 case libkbfs.WriteUnsupportedError: 59 return errorWithErrno{err, syscall.ENOENT} 60 case libkbfs.WriteToReadonlyNodeError: 61 return errorWithErrno{err, syscall.EACCES} 62 case libkbfs.UnsupportedOpInUnlinkedDirError: 63 return errorWithErrno{err, syscall.ENOENT} 64 case libkbfs.NeedSelfRekeyError: 65 return errorWithErrno{err, syscall.EACCES} 66 case libkbfs.NeedOtherRekeyError: 67 return errorWithErrno{err, syscall.EACCES} 68 case libkbfs.DisallowedPrefixError: 69 return errorWithErrno{err, syscall.EINVAL} 70 case libkbfs.NameTooLongError: 71 return errorWithErrno{err, syscall.ENAMETOOLONG} 72 case idutil.NoCurrentSessionError: 73 return errorWithErrno{err, syscall.EACCES} 74 case libkbfs.NoSuchFolderListError: 75 return errorWithErrno{err, syscall.ENOENT} 76 case libkbfs.RenameAcrossDirsError: 77 return errorWithErrno{err, syscall.EXDEV} 78 case *libkbfs.ErrDiskLimitTimeout: 79 return errorWithErrno{err, syscall.ENOSPC} 80 case libkbfs.RevGarbageCollectedError: 81 return errorWithErrno{err, syscall.ENOENT} 82 case idutil.NoSuchNameError: 83 return errorWithErrno{err, syscall.ENOENT} 84 case data.NameExistsError: 85 return errorWithErrno{err, syscall.EEXIST} 86 } 87 88 if os.IsNotExist(errors.Cause(err)) { 89 return errorWithErrno{err, syscall.ENOENT} 90 } 91 92 return err 93 }