swarm/api: fs uploader fixes

This commit is contained in:
zelig 2016-07-05 04:19:02 +02:00
parent 9b0065e05a
commit 3a7f86d61f

View file

@ -86,23 +86,26 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
errors := make([]error, cnt) errors := make([]error, cnt)
done := make(chan bool, maxParallelFiles) done := make(chan bool, maxParallelFiles)
dcnt := 0 dcnt := 0
wg := &sync.WaitGroup{} awg := &sync.WaitGroup{}
for i, entry := range list { for i, entry := range list {
if i >= dcnt+maxParallelFiles { if i >= dcnt+maxParallelFiles {
<-done <-done
dcnt++ dcnt++
} }
awg.Add(1)
go func(i int, entry *manifestTrieEntry, done chan bool) { go func(i int, entry *manifestTrieEntry, done chan bool) {
f, err := os.Open(entry.Path) f, err := os.Open(entry.Path)
if err == nil { if err == nil {
stat, _ := f.Stat() stat, _ := f.Stat()
var hash storage.Key var hash storage.Key
wg := &sync.WaitGroup{}
hash, err = self.api.dpa.Store(f, stat.Size(), wg) hash, err = self.api.dpa.Store(f, stat.Size(), wg)
if hash != nil { if hash != nil {
list[i].Hash = hash.String() list[i].Hash = hash.String()
} }
wg.Wait() wg.Wait()
awg.Done()
if err == nil { if err == nil {
first512 := make([]byte, 512) first512 := make([]byte, 512)
fread, _ := f.ReadAt(first512, 0) fread, _ := f.ReadAt(first512, 0)
@ -150,7 +153,7 @@ func (self *FileSystem) Upload(lpath, index string) (string, error) {
if err2 == nil { if err2 == nil {
hs = trie.hash.String() hs = trie.hash.String()
} }
wg.Wait() awg.Wait()
return hs, err2 return hs, err2
} }