-
Notifications
You must be signed in to change notification settings - Fork 0
/
sync_list.go
97 lines (81 loc) · 1.89 KB
/
sync_list.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
package drive
import (
"fmt"
"google.golang.org/api/drive/v3"
"google.golang.org/api/googleapi"
"io"
"sort"
"text/tabwriter"
)
type ListSyncArgs struct {
Out io.Writer
SkipHeader bool
}
func (self *Drive) ListSync(args ListSyncArgs) error {
listArgs := listAllFilesArgs{
query: "appProperties has {key='syncRoot' and value='true'}",
fields: []googleapi.Field{"nextPageToken", "files(id,name,mimeType,createdTime)"},
}
files, err := self.listAllFiles(listArgs)
if err != nil {
return err
}
printSyncDirectories(files, args)
return nil
}
type ListRecursiveSyncArgs struct {
Out io.Writer
RootId string
SkipHeader bool
PathWidth int64
SizeInBytes bool
SortOrder string
}
func (self *Drive) ListRecursiveSync(args ListRecursiveSyncArgs) error {
rootDir, err := self.getSyncRoot(args.RootId)
if err != nil {
return err
}
files, err := self.prepareRemoteFiles(rootDir, args.SortOrder)
if err != nil {
return err
}
printSyncDirContent(files, args)
return nil
}
func printSyncDirectories(files []*drive.File, args ListSyncArgs) {
w := new(tabwriter.Writer)
w.Init(args.Out, 0, 0, 3, ' ', 0)
if !args.SkipHeader {
fmt.Fprintln(w, "Id\tName\tCreated")
}
for _, f := range files {
fmt.Fprintf(w, "%s\t%s\t%s\n",
f.Id,
f.Name,
formatDatetime(f.CreatedTime),
)
}
w.Flush()
}
func printSyncDirContent(files []*RemoteFile, args ListRecursiveSyncArgs) {
if args.SortOrder == "" {
// Sort files by path
sort.Sort(byRemotePath(files))
}
w := new(tabwriter.Writer)
w.Init(args.Out, 0, 0, 3, ' ', 0)
if !args.SkipHeader {
fmt.Fprintln(w, "Id\tPath\tType\tSize\tModified")
}
for _, rf := range files {
fmt.Fprintf(w, "%s\t%s\t%s\t%s\t%s\n",
rf.file.Id,
truncateString(rf.relPath, int(args.PathWidth)),
filetype(rf.file),
formatSize(rf.file.Size, args.SizeInBytes),
formatDatetime(rf.file.ModifiedTime),
)
}
w.Flush()
}