-
Notifications
You must be signed in to change notification settings - Fork 0
/
syncdiff.go
68 lines (62 loc) · 1.48 KB
/
syncdiff.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
package main
import (
"fmt"
"github.com/ddirect/format"
"github.com/ddirect/protostream"
)
type stats struct {
count int
size int64
}
func (s *stats) update(file *File) {
s.count++
s.size += file.Size
}
func (s *stats) appendRow(t *format.Table, name string) {
if s.count > 0 {
t.AppendRow(name, s.count, format.Size(s.size))
}
}
func DiffActionsFactory(sdb *Db, ddb *Db, basePath string, ps protostream.ReadWriter) SyncActions {
sdirCount := len(sdb.Dirs)
sfileCount := len(sdb.Files)
ddirCount := len(ddb.Dirs)
dfileCount := len(ddb.Files)
var createdDirs, removedDirs int
var copied, linked, stashed, removed stats
return &syncActions{
CreateDir: func(*Dir) {
createdDirs++
},
RemoveDir: func(*Dir) {
removedDirs++
},
RemoveFile: func(f *File) {
removed.update(f)
},
CopyFile: func(f *File) {
copied.update(f)
},
LinkFile: func(f *File, _ *File) {
linked.update(f)
},
StashFile: func(f *File) {
stashed.update(f)
},
Epilogue: func() {
var s, d, f format.Table
s.AppendRow(".", "remote", "local")
s.AppendRow("total dirs", sdirCount, ddirCount)
s.AppendRow("total files", sfileCount, dfileCount)
d.AppendRow("dirs", "count")
d.AppendRow("created", createdDirs)
d.AppendRow("removed", removedDirs)
f.AppendRow("files", "count", "size")
copied.appendRow(&f, "copied")
linked.appendRow(&f, "linked")
removed.appendRow(&f, "removed")
stashed.appendRow(&f, "stashed")
fmt.Printf("%s\n%s\n%s", &s, &d, &f)
},
}
}