github.com/keybase/client/go@v0.0.0-20241007131713-f10651d043c8/kbfs/libdokan/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 package libdokan 6 7 import ( 8 "github.com/keybase/client/go/kbfs/data" 9 "github.com/keybase/client/go/kbfs/dokan" 10 "github.com/keybase/client/go/kbfs/libkbfs" 11 "golang.org/x/net/context" 12 ) 13 14 // SyncFromServerFile represents a write-only file when any write of 15 // at least one byte triggers a sync of the folder from the server. 16 // A sync: 17 // 18 // - Waits for any outstanding conflict resolution tasks to finish 19 // (and it fails if the TLF is still in staged mode after waiting for 20 // CR). 21 // - Checks with the server for what the latest revision is for the folder. 22 // - Fetches and applies any missing revisions. 23 // - Waits for all outstanding block archive tasks to complete. 24 // - Waits for all outstanding quota reclamation tasks to complete. 25 type SyncFromServerFile struct { 26 folder *Folder 27 specialWriteFile 28 } 29 30 // WriteFile implements writes for dokan. 31 func (f *SyncFromServerFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) { 32 f.folder.fs.logEnter(ctx, "SyncFromServerFile Write") 33 defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }() 34 if len(bs) == 0 { 35 return 0, nil 36 } 37 folderBranch := f.folder.getFolderBranch() 38 if folderBranch == (data.FolderBranch{}) { 39 // Nothing to do. 40 return len(bs), nil 41 } 42 err = f.folder.fs.config.KBFSOps().SyncFromServer( 43 ctx, folderBranch, nil) 44 if err != nil { 45 return 0, err 46 } 47 f.folder.fs.NotificationGroupWait() 48 return len(bs), nil 49 }