/
cmd_test_fsnotify.go
133 lines (118 loc) · 3.07 KB
/
cmd_test_fsnotify.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package client
import (
"fmt"
"time"
"golang.org/x/net/context"
"github.com/keybase/cli"
"github.com/keybase/client/go/libcmdline"
"github.com/keybase/client/go/libkb"
keybase1 "github.com/keybase/client/go/protocol/keybase1"
)
func NewCmdTestFSNotify(cl *libcmdline.CommandLine, g *libkb.GlobalContext) cli.Command {
return cli.Command{
Name: "test-fsnotify",
Usage: "Test kbfs notifications",
Action: func(c *cli.Context) {
cl.ChooseCommand(&CmdTestFSNotify{Contextified: libkb.NewContextified(g)}, "test-fsnotify", c)
},
Flags: []cli.Flag{
cli.StringFlag{
Name: "t, type",
Usage: "type of the folder: private [default], public or team",
},
cli.StringFlag{
Name: "f, filename",
Usage: "filename",
},
cli.StringFlag{
Name: "a, action",
Usage: "[encrypting|decrypting|signing|verifying|rekeying]",
},
cli.StringFlag{
Name: "delay",
Usage: "delay between start and finish calls",
},
},
}
}
type CmdTestFSNotify struct {
libkb.Contextified
folderType keybase1.FolderType
filename string
action keybase1.FSNotificationType
delay time.Duration
}
func (s *CmdTestFSNotify) ParseArgv(ctx *cli.Context) error {
s.folderType = keybase1.FolderType_PRIVATE
switch ctx.String("type") {
case "private":
// Already set.
case "public":
s.folderType = keybase1.FolderType_PUBLIC
case "team":
s.folderType = keybase1.FolderType_TEAM
default:
return fmt.Errorf("Unknown folder type: %s", ctx.String("type"))
}
s.filename = ctx.String("filename")
if len(s.filename) == 0 {
s.filename = "user.go"
}
switch ctx.String("action") {
default:
s.action = keybase1.FSNotificationType_ENCRYPTING
case "encrypting":
s.action = keybase1.FSNotificationType_ENCRYPTING
case "decrypting":
s.action = keybase1.FSNotificationType_DECRYPTING
case "signing":
s.action = keybase1.FSNotificationType_SIGNING
case "verifying":
s.action = keybase1.FSNotificationType_VERIFYING
case "rekeying":
s.action = keybase1.FSNotificationType_REKEYING
}
delay := ctx.String("delay")
if len(delay) > 0 {
dur, err := time.ParseDuration(delay)
if err != nil {
return err
}
s.delay = dur
} else {
s.delay = 1 * time.Second
}
return nil
}
func (s *CmdTestFSNotify) GetUsage() libkb.Usage {
return libkb.Usage{}
}
func (s *CmdTestFSNotify) Run() (err error) {
s.G().Log.Debug("+ CmdTestFSNotify.Run")
defer func() { s.G().Log.Debug("- CmdTestFSNotify.Run -> %s", libkb.ErrToOk(err)) }()
cli, err := GetKBFSClient(s.G())
if err != nil {
return err
}
arg := keybase1.FSNotification{
FolderType: s.folderType,
Filename: s.filename,
NotificationType: s.action,
StatusCode: keybase1.FSStatusCode_START,
}
s.G().Log.Debug("sending start event")
err = cli.FSEvent(context.TODO(), arg)
if err != nil {
return err
}
s.G().Log.Debug("sleeping for %s", s.delay)
time.Sleep(s.delay)
arg.StatusCode = keybase1.FSStatusCode_FINISH
s.G().Log.Debug("sending finish event")
err = cli.FSEvent(context.TODO(), arg)
if err != nil {
return err
}
s.G().Log.Debug("done with event")
return err
}