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