github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfs/tlf.go (about) 1 // Copyright 2016 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 package libfs 6 7 import ( 8 "strings" 9 10 "github.com/keybase/client/go/kbfs/kbfsmd" 11 "github.com/keybase/client/go/kbfs/libkbfs" 12 "github.com/keybase/client/go/kbfs/tlf" 13 "github.com/keybase/client/go/kbfs/tlfhandle" 14 "github.com/keybase/client/go/logger" 15 "github.com/pkg/errors" 16 "golang.org/x/net/context" 17 ) 18 19 // TlfDoesNotExist is a shortcut error for the cases a TLF does not exist and 20 // an early successful exit via FilterTLFEarlyExitError is wished. 21 type TlfDoesNotExist struct{} 22 23 // Error - implement error interface. 24 func (TlfDoesNotExist) Error() string { return "TLF does not exist" } 25 26 // FilterTLFEarlyExitError decides whether an error received while 27 // trying to create a TLF should result in showing the user an empty 28 // folder (exitEarly == true), or not. 29 func FilterTLFEarlyExitError(ctx context.Context, err error, log logger.Logger, name tlf.CanonicalName) ( 30 exitEarly bool, retErr error) { 31 switch err := errors.Cause(err).(type) { 32 case nil: 33 // No error. 34 return false, nil 35 36 case TlfDoesNotExist: 37 log.CDebugf(ctx, 38 "TLF %s does not exist, so pretending it's empty", 39 name) 40 return true, nil 41 42 case tlfhandle.WriteAccessError, kbfsmd.ServerErrorWriteAccess, 43 libkbfs.NonExistentTeamForHandleError: 44 // No permission to create TLF, so pretend it's still 45 // empty. 46 // 47 // In theory, we need to invalidate this once the TLF 48 // is created, but in practice, the Linux kernel 49 // doesn't cache readdir results, and probably not 50 // OSXFUSE either. 51 log.CDebugf(ctx, 52 "No permission to write to %s, so pretending it's empty", 53 name) 54 return true, nil 55 56 default: 57 if strings.Contains(err.Error(), "need writer access") { 58 // The service returns an untyped error when we try to 59 // write a TLF ID into an implicit team sigchain without 60 // writer permissions. 61 log.CDebugf(ctx, 62 "No permission to write to %s, so pretending it's empty", 63 name) 64 return true, nil 65 } 66 67 // Some other error. 68 return false, err 69 } 70 }