-
Notifications
You must be signed in to change notification settings - Fork 1.2k
/
sync_control_file.go
75 lines (64 loc) · 1.75 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// 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/client/go/kbfs/data"
"github.com/keybase/client/go/kbfs/libkbfs"
"github.com/keybase/client/go/kbfs/tlfhandle"
"github.com/keybase/client/go/protocol/keybase1"
"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 JournalManager for the
// given TLF.
func (a SyncAction) Execute(
ctx context.Context, c libkbfs.Config, fb data.FolderBranch,
h *tlfhandle.Handle) (err error) {
if fb == (data.FolderBranch{}) {
panic("zero fb in SyncAction.Execute")
}
// Ensure the TLF is initialized by getting the root node first.
_, _, err = c.KBFSOps().GetRootNode(ctx, h, data.MasterBranch)
if err != nil {
return err
}
switch a {
case SyncEnable:
_, err = c.KBFSOps().SetSyncConfig(
ctx, fb.Tlf, keybase1.FolderSyncConfig{
Mode: keybase1.FolderSyncMode_ENABLED,
})
case SyncDisable:
_, err = c.KBFSOps().SetSyncConfig(
ctx, fb.Tlf, keybase1.FolderSyncConfig{
Mode: keybase1.FolderSyncMode_DISABLED,
})
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
}