diff --git a/pkg/db/file.go b/pkg/db/file.go index ea5cb14..92460af 100644 --- a/pkg/db/file.go +++ b/pkg/db/file.go @@ -5,7 +5,6 @@ import ( "os" "strconv" "strings" - "sync" "time" "github.com/nektro/andesite/pkg/idata" @@ -91,19 +90,9 @@ func (File) ByPath(path string) (*File, bool) { // func (v *File) PopulateHashes(doUp bool) { - wg := new(sync.WaitGroup) for _, item := range idata.Hashes { - wg.Add(1) - idata.HashingSem.Add() - j := item - go func() { - defer idata.HashingSem.Done() - defer wg.Done() - - v.setHash(j, hash(j, v.PathFull), doUp) - }() + v.setHash(item, hash(item, v.PathFull), doUp) } - wg.Wait() } func (v *File) setHash(alg, hv string, doUp bool) { diff --git a/pkg/fsdb/fsdb.go b/pkg/fsdb/fsdb.go index cd72314..17be9b7 100644 --- a/pkg/fsdb/fsdb.go +++ b/pkg/fsdb/fsdb.go @@ -59,11 +59,15 @@ func insertFile(f *db.File) { return } // File does not exist, add + idata.HashingSem.Add() if idata.Config.VerboseFS { util.Log("fsdb:", "add:", f.Path) } - f.PopulateHashes(false) - db.CreateFile(f.Root, f.Path, f.Size, f.ModTime, f.MD5, f.SHA1, f.SHA256, f.SHA512, f.SHA3, f.BLAKE2b) + go func() { + defer idata.HashingSem.Done() + f.PopulateHashes(false) + db.CreateFile(f.Root, f.Path, f.Size, f.ModTime, f.MD5, f.SHA1, f.SHA256, f.SHA512, f.SHA3, f.BLAKE2b) + }() } func DeInit(mp map[string]string, rt string) {