-
Notifications
You must be signed in to change notification settings - Fork 1
/
sums.go
35 lines (28 loc) · 811 Bytes
/
sums.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
package filesums
import (
"fmt"
"path/filepath"
)
func NewFileSums(root string, workers int, quiet bool, progress bool) (*FileSums, error) {
sums := &FileSums{
Root: root,
Directories: make(map[string]*Directory),
Workers: workers,
Quiet: quiet,
Progress: progress,
Stats: NewStats(),
}
a, err := filepath.Abs(root)
if err != nil {
return sums, fmt.Errorf("Could not determine absolute path of %s: %s", root, err.Error())
}
sums.Root = a
if !isDir(a) {
return sums, fmt.Errorf("Directory %s does not exist, cannot manage checksums", a)
}
if err := sums.populateDirectories(); err != nil {
return sums, fmt.Errorf("Could not populate directories under %s: %s", root, err.Error())
}
sums.Stats.SetDirCount(len(sums.Directories))
return sums, nil
}