github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/reset_caches_file.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 //go:build !windows 6 // +build !windows 7 8 package libfuse 9 10 import ( 11 "bazil.org/fuse" 12 "bazil.org/fuse/fs" 13 "github.com/keybase/client/go/kbfs/libkbfs" 14 "golang.org/x/net/context" 15 ) 16 17 // ResetCachesFile represents a write-only file where any write of at 18 // least one byte triggers the resetting of all data caches. It can 19 // be reached from any directory under the FUSE mountpoint. Note that 20 // it does not clear the *node* cache, which means that the 21 // BlockPointers for existing nodes are still cached, such that 22 // directory listings can still be implicitly cached for nodes still 23 // being held by the kernel. 24 type ResetCachesFile struct { 25 fs *FS 26 } 27 28 var _ fs.Node = (*ResetCachesFile)(nil) 29 30 // Attr implements the fs.Node interface for ResetCachesFile. 31 func (f *ResetCachesFile) Attr(ctx context.Context, a *fuse.Attr) error { 32 a.Size = 0 33 a.Mode = 0222 34 return nil 35 } 36 37 var _ fs.Handle = (*ResetCachesFile)(nil) 38 39 var _ fs.HandleWriter = (*ResetCachesFile)(nil) 40 41 // Write implements the fs.HandleWriter interface for ResetCachesFile. 42 func (f *ResetCachesFile) Write(ctx context.Context, req *fuse.WriteRequest, 43 resp *fuse.WriteResponse) (err error) { 44 f.fs.log.CDebugf(ctx, "ResetCachesFile Write") 45 defer func() { err = f.fs.processError(ctx, libkbfs.WriteMode, err) }() 46 if len(req.Data) == 0 { 47 return nil 48 } 49 f.fs.config.ResetCaches() 50 resp.Size = len(req.Data) 51 return nil 52 }