Improved shared SHA dir

This commit is contained in:
Meutel 2017-07-08 15:15:28 +02:00
parent bb1ac4fe40
commit 865b0a1c88

View File

@ -6,10 +6,9 @@ import "io"
import "log"
import "os"
import "path/filepath"
import "sync/atomic"
import "time"
var chan_hash chan string
var running int32
func walk(path string, info os.FileInfo, err error) error {
if err != nil {
@ -20,7 +19,6 @@ func walk(path string, info os.FileInfo, err error) error {
if info.IsDir() {
return nil
} else {
atomic.AddInt32(&running, 1)
go hash(info.Name(), path)
}
return nil
@ -54,10 +52,12 @@ func main() {
if err := filepath.Walk(os.Args[1], walk); err != nil {
panic(err)
}
for str := range chan_hash {
for {
select {
case str := <-chan_hash:
fmt.Println(str)
atomic.AddInt32(&running, -1)
if running <= 0 {
case <-time.After(10 * time.Millisecond):
return
}
}