Improved shared SHA dir
This commit is contained in:
parent
bb1ac4fe40
commit
865b0a1c88
@ -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 {
|
||||
fmt.Println(str)
|
||||
atomic.AddInt32(&running, -1)
|
||||
if running <= 0 {
|
||||
|
||||
for {
|
||||
select {
|
||||
case str := <-chan_hash:
|
||||
fmt.Println(str)
|
||||
case <-time.After(10 * time.Millisecond):
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user