forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_from_server_file.go
48 lines (44 loc) · 1.51 KB
/
sync_from_server_file.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2016 Keybase Inc. All rights reserved.
// Use of this source code is governed by a BSD
// license that can be found in the LICENSE file.
package libdokan
import (
"github.com/keybase/kbfs/dokan"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
// SyncFromServerFile represents a write-only file when any write of
// at least one byte triggers a sync of the folder from the server.
// A sync:
//
// - Waits for any outstanding conflict resolution tasks to finish
// (and it fails if the TLF is still in staged mode after waiting for
// CR).
// - Checks with the server for what the latest revision is for the folder.
// - Fetches and applies any missing revisions.
// - Waits for all outstanding block archive tasks to complete.
// - Waits for all outstanding quota reclamation tasks to complete.
type SyncFromServerFile struct {
folder *Folder
specialWriteFile
}
// WriteFile implements writes for dokan.
func (f *SyncFromServerFile) WriteFile(ctx context.Context, fi *dokan.FileInfo, bs []byte, offset int64) (n int, err error) {
f.folder.fs.logEnter(ctx, "SyncFromServerFile Write")
defer func() { f.folder.reportErr(ctx, libkbfs.WriteMode, err) }()
if len(bs) == 0 {
return 0, nil
}
folderBranch := f.folder.getFolderBranch()
if folderBranch == (libkbfs.FolderBranch{}) {
// Nothing to do.
return len(bs), nil
}
err = f.folder.fs.config.KBFSOps().SyncFromServerForTesting(
ctx, folderBranch)
if err != nil {
return 0, err
}
f.folder.fs.NotificationGroupWait()
return len(bs), nil
}