From cb92bcb64330000fba2e3a4657b37c0a276b65bf Mon Sep 17 00:00:00 2001 From: Arnaud Ysmal Date: Thu, 20 Feb 2014 20:53:22 +0100 Subject: [PATCH] Return the ChunkUploadResponse when err is EOF --- dropbox.go | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/dropbox.go b/dropbox.go index f8f6d5a..8ffb3a5 100644 --- a/dropbox.go +++ b/dropbox.go @@ -251,13 +251,13 @@ func (self *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCl return nil, err } defer response.Body.Close() - if r.N != 0 { - return nil, io.EOF - } if body, err = ioutil.ReadAll(response.Body); err == nil { err = json.Unmarshal(body, &cur) } + if r.N != 0 { + err = io.EOF + } return &cur, err } @@ -265,21 +265,13 @@ func (self *Dropbox) ChunkedUpload(session *ChunkUploadResponse, input io.ReadCl func (self *Dropbox) UploadByChunk(input io.ReadCloser, chunksize int, dst string, overwrite bool, parentRev string) (*Entry, error) { var err error var cur *ChunkUploadResponse - var uploadId string - if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil { - return nil, err - } - uploadId = cur.UploadId for err == nil { - if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil { - if err == io.EOF { - break - } + if cur, err = self.ChunkedUpload(cur, input, chunksize); err != nil && err != io.EOF { return nil, err } } - return self.CommitChunkedUpload(uploadId, dst, overwrite, parentRev) + return self.CommitChunkedUpload(cur.UploadId, dst, overwrite, parentRev) } // Upload size bytes from the input reader to the dst path on Dropbox.