Compare commits
2 Commits
Author | SHA1 | Date | |
---|---|---|---|
250b010c7e | |||
627bb5a7be |
4
hash.go
4
hash.go
@ -32,7 +32,7 @@ func (r results) Less(i, j int) bool { return r[i].f < r[j].f }
|
|||||||
type hashr func() hash.Hash
|
type hashr func() hash.Hash
|
||||||
|
|
||||||
// hsh figures out which hash algo to use, and distributes the work of hashing
|
// hsh figures out which hash algo to use, and distributes the work of hashing
|
||||||
func hsh(files []string, verbose, recursive bool) chan result {
|
func hsh(files []string, verbose bool) chan result {
|
||||||
var h hashr
|
var h hashr
|
||||||
switch *algo {
|
switch *algo {
|
||||||
case "sha1", "1":
|
case "sha1", "1":
|
||||||
@ -69,8 +69,6 @@ func hsh(files []string, verbose, recursive bool) chan result {
|
|||||||
|
|
||||||
jobs := make(chan checksum)
|
jobs := make(chan checksum)
|
||||||
go func() {
|
go func() {
|
||||||
// if recursive then we gotta take every file that's a directory and
|
|
||||||
// recurse them babies
|
|
||||||
for _, name := range files {
|
for _, name := range files {
|
||||||
jobs <- checksum{filename: name}
|
jobs <- checksum{filename: name}
|
||||||
}
|
}
|
||||||
|
5
main.go
5
main.go
@ -9,7 +9,6 @@ import (
|
|||||||
|
|
||||||
var algo = flag.String("a", "sha256", "algorithm to use")
|
var algo = flag.String("a", "sha256", "algorithm to use")
|
||||||
var mode = flag.Bool("c", false, "check")
|
var mode = flag.Bool("c", false, "check")
|
||||||
var recursive = flag.Bool("r", false, "recursive")
|
|
||||||
var ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines")
|
var ngo = flag.Int("n", runtime.NumCPU(), "number of goroutines")
|
||||||
var verbose = flag.Bool("v", false, "vebose")
|
var verbose = flag.Bool("v", false, "vebose")
|
||||||
|
|
||||||
@ -28,12 +27,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
case false:
|
case false:
|
||||||
ec := 0
|
ec := 0
|
||||||
for res := range hsh(files, *verbose, *recursive) {
|
for res := range hsh(files, *verbose) {
|
||||||
if res.err != nil {
|
if res.err != nil {
|
||||||
ec++
|
ec++
|
||||||
fmt.Fprintf(os.Stderr, "%v\n", res.err)
|
fmt.Fprintf(os.Stderr, "%v\n", res.err)
|
||||||
} else {
|
} else {
|
||||||
fmt.Printf("%v %v\n", res.cs, res.f)
|
fmt.Printf("%v %v\n", res.cs, res.f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ec > 0 {
|
if ec > 0 {
|
||||||
|
Loading…
Reference in New Issue
Block a user