Browse Source

Starting recursive

recursive
Stephen McQuay 2 years ago
parent
commit
88c51402fd
Signed by: sm GPG Key ID: 4E4B72F479BA3CE5
2 changed files with 5 additions and 2 deletions
  1. +3
    -1
      hash.go
  2. +2
    -1
      main.go

+ 3
- 1
hash.go 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, verbose bool) chan result {
func hsh(files []string, verbose, recursive bool) chan result {
var h hashr
switch *algo {
case "sha1", "1":
@ -69,6 +69,8 @@ func hsh(files []string, verbose bool) chan result {
jobs := make(chan checksum)
go func() {
// if recursive then we gotta take every file that's a directory and
// recurse them babies
for _, name := range files {
jobs <- checksum{filename: name}
}

+ 2
- 1
main.go View File

@ -9,6 +9,7 @@ import (
var algo = flag.String("a", "sha256", "algorithm to use")
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 verbose = flag.Bool("v", false, "vebose")
@ -27,7 +28,7 @@ func main() {
}
case false:
ec := 0
for res := range hsh(files, *verbose) {
for res := range hsh(files, *verbose, *recursive) {
if res.err != nil {
ec++
fmt.Fprintf(os.Stderr, "%v\n", res.err)

Loading…
Cancel
Save