Store the filename and checksum separately

This commit is contained in:
Stephen McQuay 2017-10-18 17:42:31 -07:00
parent 691d096a39
commit 717f195cf7
Signed by: sm
GPG Key ID: 4E4B72F479BA3CE5
2 changed files with 5 additions and 4 deletions

View File

@ -14,7 +14,8 @@ import (
// result is a message or error payload
type result struct {
msg string
f string
cs string
err error
}
@ -52,7 +53,7 @@ func hsh(files []string) chan result {
fmt.Fprintf(os.Stderr, "%v\n", err)
os.Exit(1)
}
r <- result{msg: fmt.Sprintf("%x -", hsh.Sum(nil))}
r <- result{cs: fmt.Sprintf("%x", hsh.Sum(nil)), f: "-"}
close(r)
}()
return r
@ -92,7 +93,7 @@ func compute(h hashr, jobs chan checksum) chan result {
r <- result{err: err}
continue
}
r <- result{msg: fmt.Sprintf("%x %s", hsh.Sum(nil), job.filename)}
r <- result{f: job.filename, cs: fmt.Sprintf("%x", hsh.Sum(nil))}
}
close(r)
}()

View File

@ -31,7 +31,7 @@ func main() {
ec++
fmt.Fprintf(os.Stderr, "%v\n", res.err)
} else {
fmt.Printf("%v\n", res.msg)
fmt.Printf("%v %v\n", res.cs, res.f)
}
}
if ec > 0 {