diff options
author | Felix Lange <fjl@twurst.com> | 2017-01-09 18:16:06 +0800 |
---|---|---|
committer | Felix Lange <fjl@twurst.com> | 2017-01-09 23:24:42 +0800 |
commit | b9b3efb09f9281a5859646d2dcf36b5813132efb (patch) | |
tree | f9dc8f9d82108b33bec4669b09a99d06d24239a9 /swarm/api/filesystem.go | |
parent | 0f34d506b5ae9b76de97318c906e56dddd5309f6 (diff) | |
download | go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar.gz go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar.bz2 go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar.lz go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar.xz go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.tar.zst go-tangerine-b9b3efb09f9281a5859646d2dcf36b5813132efb.zip |
all: fix ineffectual assignments and remove uses of crypto.Sha3
go get github.com/gordonklaus/ineffassign
ineffassign .
Diffstat (limited to 'swarm/api/filesystem.go')
-rw-r--r-- | swarm/api/filesystem.go | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/swarm/api/filesystem.go b/swarm/api/filesystem.go index 428f3e3ac..96aaf36df 100644 --- a/swarm/api/filesystem.go +++ b/swarm/api/filesystem.go @@ -241,24 +241,7 @@ func (self *FileSystem) Download(bzzpath, localpath string) error { } go func(i int, entry *downloadListEntry) { defer wg.Done() - f, err := os.Create(entry.path) // TODO: path separators - if err == nil { - - reader := self.api.dpa.Retrieve(entry.key) - writer := bufio.NewWriter(f) - size, err := reader.Size(quitC) - if err == nil { - _, err = io.CopyN(writer, reader, size) // TODO: handle errors - err2 := writer.Flush() - if err == nil { - err = err2 - } - err2 = f.Close() - if err == nil { - err = err2 - } - } - } + err := retrieveToFile(quitC, self.api.dpa, entry.key, entry.path) if err != nil { select { case errC <- err: @@ -279,5 +262,24 @@ func (self *FileSystem) Download(bzzpath, localpath string) error { case <-quitC: return fmt.Errorf("aborted") } +} +func retrieveToFile(quitC chan bool, dpa *storage.DPA, key storage.Key, path string) error { + f, err := os.Create(path) // TODO: path separators + if err != nil { + return err + } + reader := dpa.Retrieve(key) + writer := bufio.NewWriter(f) + size, err := reader.Size(quitC) + if err != nil { + return err + } + if _, err = io.CopyN(writer, reader, size); err != nil { + return err + } + if err := writer.Flush(); err != nil { + return err + } + return f.Close() } |