-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathfind.go
60 lines (51 loc) · 1.32 KB
/
find.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
package watchman
import (
"github.com/yookoala/realpath"
)
// Find is the return object of the Find call
type Find struct {
Clock string `bser:"clock"`
Files []File `bser:"files"`
}
// File represents a file on the filesystem
type File struct {
Cclock string `bser:"cclock"`
Ctime int `bser:"ctime"`
Dev int `bser:"dev"`
Exists bool `bser:"exists"`
Gid int `bser:"gid"`
Ino int `bser:"ino"`
Mode int `bser:"mode"`
Mtime int `bser:"mtime"`
Name string `bser:"name"`
New bool `bser:"new"`
Nlink int `bser:"nlink"`
Oclock string `bser:"oclock"`
Size int `bser:"size"`
UID int `bser:"uid"`
}
// Find finds all files that match the optional list of patterns under the specified dir. If no patterns were specified, all files are returned.
// https://facebook.github.io/watchman/docs/cmd/find.html
func (c *Client) Find(path string, patterns ...string) (*Find, error) {
path, err := realpath.Realpath(path)
if err != nil {
return nil, err
}
var data struct {
base
Find
}
args := make([]interface{}, len(patterns)+2)
args[0] = "find"
args[1] = path
for i := 0; i < len(patterns); i++ {
args[i+2] = patterns[i]
}
if err := c.Send(&data, args...); err != nil {
return nil, err
}
if data.Error != "" {
return nil, data.Error
}
return &data.Find, nil
}