forked from keybase/kbfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_control_file.go
60 lines (50 loc) · 1.28 KB
/
sync_control_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
49
50
51
52
53
54
55
56
57
58
59
60
// Copyright 2017 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 libfs
import (
"fmt"
"github.com/keybase/kbfs/libkbfs"
"golang.org/x/net/context"
)
// SyncAction enumerates all the possible actions to take on a
// TLF's sync state.
type SyncAction int
const (
// SyncEnable is to enable syncing for a TLF.
SyncEnable SyncAction = iota
// SyncDisable is to disable syncing for a TLF.
SyncDisable
)
func (a SyncAction) String() string {
switch a {
case SyncEnable:
return "Enable syncing"
case SyncDisable:
return "Disable syncing"
}
return fmt.Sprintf("SyncAction(%d)", int(a))
}
// Execute performs the action on the given JournalServer for the
// given TLF.
func (a SyncAction) Execute(
ctx context.Context, c libkbfs.Config, fb libkbfs.FolderBranch,
h *libkbfs.TlfHandle) (err error) {
if fb == (libkbfs.FolderBranch{}) {
panic("zero fb in SyncAction.Execute")
}
switch a {
case SyncEnable:
err = c.SetTlfSyncState(fb.Tlf, true)
case SyncDisable:
err = c.SetTlfSyncState(fb.Tlf, false)
default:
return fmt.Errorf("Unknown action %s", a)
}
if err != nil {
return err
}
// Re-trigger prefetches.
_, _, err = c.KBFSOps().GetRootNode(ctx, h, fb.Branch)
return err
}