github.com/keybase/client/go@v0.0.0-20240309051027-028f7c731f8b/kbfs/libfuse/unstage_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/libfs" 14 "github.com/keybase/client/go/kbfs/libkbfs" 15 "golang.org/x/net/context" 16 ) 17 18 // UnstageFile represents a write-only file when any write of at least 19 // one byte triggers unstaging all unmerged commits and 20 // fast-forwarding to the current master. 21 type UnstageFile struct { 22 folder *Folder 23 } 24 25 var _ fs.Node = (*UnstageFile)(nil) 26 27 // Attr implements the fs.Node interface for UnstageFile. 28 func (f *UnstageFile) Attr(ctx context.Context, a *fuse.Attr) error { 29 a.Size = 0 30 a.Mode = 0222 31 return nil 32 } 33 34 var _ fs.Handle = (*UnstageFile)(nil) 35 36 var _ fs.HandleWriter = (*UnstageFile)(nil) 37 38 // Write implements the fs.HandleWriter interface for UnstageFile. 39 func (f *UnstageFile) Write(ctx context.Context, req *fuse.WriteRequest, 40 resp *fuse.WriteResponse) (err error) { 41 defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() 42 size, err := libfs.UnstageForTesting( 43 ctx, f.folder.fs.log, f.folder.fs.config, 44 f.folder.getFolderBranch(), req.Data) 45 if err != nil { 46 return err 47 } 48 resp.Size = size 49 return nil 50 }