Skip to content

Commit

Permalink
Explicitly get JFSIncompleteFile again if .size is not returned from …
Browse files Browse the repository at this point in the history
…the server (this is the default in e.g. a file listing)

Closes #81 and #104
  • Loading branch information
havardgulldahl committed Jul 12, 2016
1 parent 39d4cdf commit 3ecf5de
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions src/jottalib/JFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -490,6 +490,15 @@ def resume(self, data):
'Resume uploading an incomplete file, after a previous upload was interrupted. Returns new file object'
if not hasattr(data, 'read'):
data = StringIO(data)

#Check that we actually know from what byte to resume.
#If self.size === -1, it means we never got the value from the server.
#This is perfectly normal if the file was instatiated via e.g. a file listing,
#and not directly via JFS.getObject()
if self.size == -1:
log.debug('%r is an incomplete file, but .size is unknown. Refreshing the file object from server', self.path)
self.f = self.jfs.get(self.path)

#check if what we're asked to upload is actually the right file
md5 = calculate_md5(data)
if md5 != self.md5:
Expand Down

0 comments on commit 3ecf5de

Please sign in to comment.