-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.go
127 lines (110 loc) · 3.76 KB
/
main.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
// Program godupless creates a report of duplicate files across multiple volumes
package main
import (
"flag"
"fmt"
"github.com/rasa/godupless/dupless"
"github.com/rasa/godupless/report"
"github.com/rasa/godupless/version"
"os"
"path/filepath"
"runtime"
"strings"
)
type config struct {
// DiffReport @todo
DiffReport bool
// DirReport @todo
DirReport bool
// ErrorReport @todo
ErrorReport bool
// HardLinkReport @todo
HardLinkReport bool
// IgnoredReport @todo
IgnoredReport bool
// SizeReport @todo
SizeReport bool
}
var defaultConfig = config{
//DiffReport: false,
//DirReport: false,
//ErrorReport: false,
//HardLinkReport: false,
//IgnoredReport: false,
SizeReport: true,
}
func usage() {
fmt.Fprintf(os.Stderr, "\nUsage: %s [options] path [path2] ...\nOptions:\n\n", os.Args[0])
flag.PrintDefaults()
}
func main() {
basename := filepath.Base(os.Args[0])
progname := strings.TrimSuffix(basename, filepath.Ext(basename))
fmt.Printf("%s: Version %s (%s)\n", progname, version.VERSION, version.GITCOMMIT)
fmt.Printf("Built with %s for %s/%s (%d CPUs/%d GOMAXPROCS)\n",
runtime.Version(),
runtime.GOOS,
runtime.GOARCH,
runtime.NumCPU(),
runtime.GOMAXPROCS(-1))
c := dupless.DefaultConfig
d := dupless.New(c)
chunk := fmt.Sprintf("Hash chunk size (%d to %d)", dupless.MinChunk, dupless.MaxChunk)
hash := "Hash type: " + dupless.Hashes()
// flag.StringVar(&d.Config.Cache, "cache", d.Config.Cache, "Cache filename")
flag.UintVar(&c.Chunk, "chunk", c.Chunk, chunk)
flag.StringVar(&c.Exclude, "exclude", c.Exclude, "Regex(s) of directories/files to exclude, separated by |")
flag.StringVar(&c.Iexclude, "iexclude", c.Iexclude, "Regex(s) of directories/files to exclude, separated by |")
//flag.BoolVar(&c.Extra, "extra", c.Extra, "Cache extra attributes")
flag.UintVar(&c.Freq, "frequency", c.Freq, "Reporting frequency")
flag.StringVar(&c.Hash, "hash", c.Hash, hash)
flag.BoolVar(&c.Help, "help", c.Help, "Display help")
flag.StringVar(&c.Mask, "mask", c.Mask, "File mask(s), seperated by |")
flag.UintVar(&c.MinFiles, "min_files", c.MinFiles, "Minimum files to compare")
flag.Uint64Var(&c.MinSize, "min_size", c.MinSize, "Minimum file size")
flag.BoolVar(&c.Recursive, "recursive", c.Recursive, "Report directories recursively")
//flag.StringVar(&c.Seperator, "separator", c.Seperator, "Field separator")
// flag.BoolVar(&c.Utc, "utc", c.Utc, "Report times in UTC")
flag.IntVar(&c.Verbose, "verbose", c.Verbose, "Increase log verbosity")
flag.BoolVar(&defaultConfig.DiffReport, "diff_report", defaultConfig.DiffReport, "Report on differences between directories containing duplicate files")
flag.BoolVar(&defaultConfig.DirReport, "dir_report", defaultConfig.DirReport, "Report summary of duplicates by directory")
flag.BoolVar(&defaultConfig.ErrorReport, "error_report", defaultConfig.ErrorReport, "Report of errors")
flag.BoolVar(&defaultConfig.HardLinkReport, "hard_link_report", defaultConfig.HardLinkReport, "Report on hard link differences")
flag.BoolVar(&defaultConfig.IgnoredReport, "ignored_report", defaultConfig.IgnoredReport, "Report of ignored files")
flag.BoolVar(&defaultConfig.SizeReport, "size_report", defaultConfig.SizeReport, "Report duplicates by size")
flag.Parse()
c.Validate()
rv := d.Run()
if !rv {
if d.Config.Help {
usage()
}
os.Exit(1)
}
if defaultConfig.ErrorReport {
r := report.NewErrorReport(d)
r.Run()
}
if defaultConfig.IgnoredReport {
r := report.NewIgnoredReport(d)
r.Run()
}
if defaultConfig.HardLinkReport {
r := report.NewHardLinkReport(d)
r.Run()
}
if defaultConfig.DiffReport {
r := report.NewDiffReport(d)
r.Run()
}
if defaultConfig.DirReport {
r := report.NewDirReport(d)
r.Run()
}
if defaultConfig.SizeReport {
r := report.NewSizeReport(d)
r.Run()
}
d.Footer()
os.Exit(0)
}