From 3a7f86d61f9825fa7bd634104d56d78fd80a67b4 Mon Sep 17 00:00:00 2001 From: zelig Date: Tue, 5 Jul 2016 04:19:02 +0200 Subject: [PATCH] swarm/api: fs uploader fixes --- swarm/api/filesystem.go | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go index cc8fd2c818..ac09602bc6 100644 --- a/swarm/api/filesystem.go +++ b/swarm/api/filesystem.go @@ -86,23 +86,26 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) { errors := make([]error, cnt) done := make(chan bool, maxParallelFiles) dcnt := 0 - wg := &sync.WaitGroup{} + awg := &sync.WaitGroup{} for i, entry := range list { if i >= dcnt+maxParallelFiles { <-done dcnt++ } + awg.Add(1) go func(i int, entry *manifestTrieEntry, done chan bool) { f, err := os.Open(entry.Path) if err == nil { stat, _ := f.Stat() var hash storage.Key + wg := &sync.WaitGroup{} hash, err = self.api.dpa.Store(f, stat.Size(), wg) if hash != nil { list[i].Hash = hash.String() } wg.Wait() + awg.Done() if err == nil { first512 := make([]byte, 512) fread, _ := f.ReadAt(first512, 0) @@ -150,7 +153,7 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) { if err2 == nil { hs = trie.hash.String() } - wg.Wait() + awg.Wait() return hs, err2 }