mirror of
https://github.com/vbatts/dedupe-linker.git
synced 2025-02-05 20:03:34 +00:00
for the time being, no wait group. just channel
This commit is contained in:
parent
e6cc87db96
commit
71419f8faa
1 changed files with 3 additions and 15 deletions
14
file/hash.go
14
file/hash.go
|
@ -6,7 +6,6 @@ import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
"sync"
|
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
@ -23,7 +22,6 @@ type FileHashInfo struct {
|
||||||
func HashFileGetter(path string, hash crypto.Hash, workers int, done <-chan struct{}) <-chan FileHashInfo {
|
func HashFileGetter(path string, hash crypto.Hash, workers int, done <-chan struct{}) <-chan FileHashInfo {
|
||||||
out := make(chan FileHashInfo, workers)
|
out := make(chan FileHashInfo, workers)
|
||||||
go func() {
|
go func() {
|
||||||
var wg sync.WaitGroup
|
|
||||||
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
err := filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
|
@ -31,15 +29,8 @@ func HashFileGetter(path string, hash crypto.Hash, workers int, done <-chan stru
|
||||||
if !info.Mode().IsRegular() {
|
if !info.Mode().IsRegular() {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
wg.Add(1)
|
|
||||||
go func() {
|
|
||||||
fhi := hashFile(path, hash, info)
|
fhi := hashFile(path, hash, info)
|
||||||
select {
|
out <- *fhi
|
||||||
case out <- *fhi:
|
|
||||||
case <-done:
|
|
||||||
}
|
|
||||||
wg.Done()
|
|
||||||
}()
|
|
||||||
select {
|
select {
|
||||||
case <-done:
|
case <-done:
|
||||||
return fmt.Errorf("walk canceled")
|
return fmt.Errorf("walk canceled")
|
||||||
|
@ -50,11 +41,8 @@ func HashFileGetter(path string, hash crypto.Hash, workers int, done <-chan stru
|
||||||
if err != nil {
|
if err != nil {
|
||||||
out <- FileHashInfo{Err: err}
|
out <- FileHashInfo{Err: err}
|
||||||
}
|
}
|
||||||
go func() {
|
|
||||||
wg.Wait()
|
|
||||||
close(out)
|
close(out)
|
||||||
}()
|
}()
|
||||||
}()
|
|
||||||
return out
|
return out
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue