-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
92 lines (85 loc) · 2.14 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
package main
import (
"compress/gzip"
"flag"
"fmt"
"os"
"runtime"
)
func printUsage() {
fmt.Fprintf(
os.Stderr,
"Usage of %s: [options] [path ...]\n%s recurses over paths provided as arguments or gets the file list form stdin otherwize\nOptions:\n",
os.Args[0],
os.Args[0],
)
flag.PrintDefaults()
}
func main() {
p := flag.Int("p", 1, "# of cpu used")
jobCountP := flag.Int("j", 1, "# of parallel reads")
listQueueLength := flag.Int("l", 100, "size of list ahead queue")
readSizeP := flag.Int("s", 1, "size of reads in kbytes")
outFile := flag.String("out", "", "write CRC to file")
outErr := flag.String("errout", "", "write errors to file")
compress := flag.Bool("c", false, "enable file output compression")
flag.Usage = printUsage
flag.Parse()
runtime.GOMAXPROCS(*p) // limit number of kernel threads (CPUs used)
mc := InitMassCRC32C(*readSizeP, *listQueueLength)
if *outFile != "" {
f, err := os.OpenFile(*outFile, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
os.Exit(2)
}
defer f.Close()
if *compress {
gzWriter := gzip.NewWriter(f)
defer func(gzWriter *gzip.Writer) {
err := gzWriter.Flush()
if err != nil {
fmt.Fprintf(mc.DebugOut, "Error: failed to flush gzip stream: %v", err)
}
err = gzWriter.Close()
if err != nil {
fmt.Fprintf(mc.DebugOut, "Error: failed to close gzip stream: %v", err)
}
}(gzWriter)
mc.StdOut = gzWriter
} else {
mc.StdOut = f
}
}
if *outErr != "" {
f, err := os.OpenFile(*outErr, os.O_WRONLY|os.O_CREATE, 0644)
if err != nil {
os.Exit(2)
}
defer f.Close()
if *compress {
gzWriter := gzip.NewWriter(f)
defer func(gzWriter *gzip.Writer) {
err := gzWriter.Flush()
if err != nil {
fmt.Fprintf(mc.DebugOut, "Error: failed to flush gzip stream: %v", err)
}
err = gzWriter.Close()
if err != nil {
fmt.Fprintf(mc.DebugOut, "Error: failed to close gzip stream: %v", err)
}
}(gzWriter)
mc.ErrOut = gzWriter
} else {
mc.ErrOut = f
}
}
mc.Startup(*jobCountP)
fi := FileInput{mc: mc}
if flag.NArg() == 0 {
fi.ReadFileList()
} else {
fi.WalkDirectories()
}
mc.TearDown()
mc.PrintSummary()
}