Refactoring SHA dir: shorter
This commit is contained in:
parent
e75afaf5e6
commit
5a237532fa
@ -24,12 +24,12 @@ func main() {
|
|||||||
log.Fatalln("Usage shadir file")
|
log.Fatalln("Usage shadir file")
|
||||||
}
|
}
|
||||||
|
|
||||||
var wg sync.WaitGroup
|
|
||||||
chan_hash, chan_path := make(chan string), make(chan string)
|
chan_hash, chan_path := make(chan string), make(chan string)
|
||||||
|
|
||||||
|
go func() { // 100 routines hashing
|
||||||
|
var wg sync.WaitGroup
|
||||||
for i := 0; i < 100; i++ {
|
for i := 0; i < 100; i++ {
|
||||||
wg.Add(1)
|
wg.Add(1)
|
||||||
go func() {
|
|
||||||
for path := range chan_path {
|
for path := range chan_path {
|
||||||
if h, err := sha256File(path); err != nil {
|
if h, err := sha256File(path); err != nil {
|
||||||
log.Print("Error "+path, err)
|
log.Print("Error "+path, err)
|
||||||
@ -38,14 +38,12 @@ func main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
|
||||||
}
|
}
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
close(chan_hash)
|
close(chan_hash)
|
||||||
}()
|
}()
|
||||||
|
|
||||||
go func() {
|
go func() { // walk through files
|
||||||
filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error {
|
filepath.Walk(os.Args[1], func(path string, info os.FileInfo, err error) error {
|
||||||
if err == nil && !info.IsDir() {
|
if err == nil && !info.IsDir() {
|
||||||
chan_path <- path
|
chan_path <- path
|
||||||
|
Loading…
Reference in New Issue
Block a user