github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/reclaim_quota_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 // ReclaimQuotaFile represents a write-only file when any write of at 18 // least one byte triggers a quota reclamation of the folder. 19 type ReclaimQuotaFile struct { 20 folder *Folder 21 } 22 23 var _ fs.Node = (*ReclaimQuotaFile)(nil) 24 25 // Attr implements the fs.Node interface for ReclaimQuotaFile. 26 func (f *ReclaimQuotaFile) Attr(ctx context.Context, a *fuse.Attr) error { 27 a.Size = 0 28 a.Mode = 0222 29 return nil 30 } 31 32 var _ fs.Handle = (*ReclaimQuotaFile)(nil) 33 34 var _ fs.HandleWriter = (*ReclaimQuotaFile)(nil) 35 36 // Write implements the fs.HandleWriter interface for 37 // ReclaimQuotaFile. Note a write triggers quota reclamation, but 38 // does not wait for it to finish. If you want to wait, write to 39 // SyncFromServerFileName. 40 func (f *ReclaimQuotaFile) Write(ctx context.Context, req *fuse.WriteRequest, 41 resp *fuse.WriteResponse) (err error) { 42 f.folder.fs.log.CDebugf(ctx, "ReclaimQuotaFile Write") 43 defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() 44 if len(req.Data) == 0 { 45 return nil 46 } 47 err = libkbfs.ForceQuotaReclamationForTesting( 48 f.folder.fs.config, f.folder.getFolderBranch()) 49 if err != nil { 50 return err 51 } 52 resp.Size = len(req.Data) 53 return nil 54 }