Added verbose mode

This commit is contained in:
sm
2017-10-18 18:03:16 -07:00
parent 98d5dd7033
commit 9017579805
3 changed files with 14 additions and 8 deletions
+6 -3
View File
@@ -32,7 +32,7 @@ func (r results) Less(i, j int) bool { return r[i].f < r[j].f }
type hashr func() hash.Hash
// hsh figures out which hash algo to use, and distributes the work of hashing
func hsh(files []string) chan result {
func hsh(files []string, verbose bool) chan result {
var h hashr
switch *algo {
case "sha1", "1":
@@ -77,7 +77,7 @@ func hsh(files []string) chan result {
res := []<-chan result{}
for w := 0; w < *ngo; w++ {
res = append(res, compute(h, jobs))
res = append(res, compute(h, jobs, verbose))
}
o := make(chan result)
@@ -96,7 +96,7 @@ func hsh(files []string) chan result {
}
// compute is the checksumming workhorse
func compute(h hashr, jobs chan checksum) chan result {
func compute(h hashr, jobs chan checksum, verbose bool) chan result {
hsh := h()
r := make(chan result)
go func() {
@@ -113,6 +113,9 @@ func compute(h hashr, jobs chan checksum) chan result {
r <- result{err: err}
continue
}
if verbose {
fmt.Fprintf(os.Stderr, "%v\n", job.filename)
}
r <- result{f: job.filename, cs: fmt.Sprintf("%x", hsh.Sum(nil))}
}
close(r)