github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libfuse/sync_from_server_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/data" 14 "github.com/keybase/client/go/kbfs/libfs" 15 "github.com/keybase/client/go/kbfs/libkbfs" 16 "golang.org/x/net/context" 17 ) 18 19 // SyncFromServerFile represents a write-only file when any write of 20 // at least one byte triggers a sync of the folder from the server. 21 // A sync: 22 // 23 // - Waits for any outstanding conflict resolution tasks to finish 24 // (and it fails if the TLF is still in staged mode after waiting for 25 // CR). 26 // - Checks with the server for what the latest revision is for the folder. 27 // - Fetches and applies any missing revisions. 28 // - Waits for all outstanding block archive tasks to complete. 29 // - Waits for all outstanding quota reclamation tasks to complete. 30 type SyncFromServerFile struct { 31 folder *Folder 32 } 33 34 var _ fs.Node = (*SyncFromServerFile)(nil) 35 36 // Attr implements the fs.Node interface for SyncFromServerFile. 37 func (f *SyncFromServerFile) Attr(ctx context.Context, a *fuse.Attr) error { 38 a.Size = 0 39 a.Mode = 0222 40 return nil 41 } 42 43 var _ fs.Handle = (*SyncFromServerFile)(nil) 44 45 var _ fs.HandleWriter = (*SyncFromServerFile)(nil) 46 47 // Write implements the fs.HandleWriter interface for SyncFromServerFile. 48 func (f *SyncFromServerFile) Write(ctx context.Context, req *fuse.WriteRequest, 49 resp *fuse.WriteResponse) (err error) { 50 f.folder.fs.log.CDebugf(ctx, "SyncFromServerFile Write") 51 defer func() { err = f.folder.processError(ctx, libkbfs.WriteMode, err) }() 52 if len(req.Data) == 0 { 53 return nil 54 } 55 folderBranch := f.folder.getFolderBranch() 56 if folderBranch == (data.FolderBranch{}) { 57 // Nothing to do. 58 resp.Size = len(req.Data) 59 return nil 60 } 61 62 // Use a context with a nil CtxAppIDKey value so that 63 // notifications generated from this sync won't be discarded. 64 syncCtx := context.WithValue(ctx, libfs.CtxAppIDKey, nil) 65 err = f.folder.fs.config.KBFSOps().SyncFromServer( 66 syncCtx, folderBranch, nil) 67 if err != nil { 68 return err 69 } 70 f.folder.fs.NotificationGroupWait() 71 resp.Size = len(req.Data) 72 return nil 73 }