Skip to content

Commit

Permalink
When resuming uploads, restart upload if seeking in the source file f…
Browse files Browse the repository at this point in the history
…ails. Related to #104 and #81.
  • Loading branch information
havardgulldahl committed Jul 28, 2016
1 parent 3ecf5de commit 731de6a
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 3 deletions.
13 changes: 13 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,18 @@
# Change Log


## [0.5.1] - TBA

### Bug fixes

- Check that we actually know from what byte to resume in the case of Incomplete files. Previously this would abort e.g. `jotta-scanner`, because it pulled file listings in a way that doesn't return incomplete file sizes. See issue #104 and #81. Thanks, @cowai and @jnylen for reports.
- When resuming uploads, restart upload if seeking in the source file fails. Related to the issue above.

### Changed

-


## [0.5] - 2016-07-02

### Regressions
Expand Down
14 changes: 11 additions & 3 deletions src/jottalib/JFS.py
Original file line number Diff line number Diff line change
Expand Up @@ -1120,13 +1120,21 @@ def up(self, path, fileobject, upload_callback=None, resume_offset=None):
contentlen = fileobject.tell()

# Rewind read head to correct offset
# If we're resuming a borked upload, continue from that offset
fileobject.seek(resume_offset if resume_offset is not None else 0)
# If we're resuming an incomplete upload, continue from that offset
try:
fileobject.seek(resume_offset)
except IOError as e:
if resume_offset is not None and resume_offset > 0:
log.exception(e)
log.warning('Could not seek to file offset %r, re-starting upload of %r from 0',
resume_offset,
url)


# Calculate file md5 hash
md5hash = calculate_md5(fileobject)

log.debug('posting content (len %s, hash %s) to url %s', contentlen, md5hash, url)
log.debug('posting content (len %s, hash %s) to url %r', contentlen, md5hash, url)
try:
mtime = os.path.getmtime(fileobject.name)
timestamp = datetime.datetime.fromtimestamp(mtime).isoformat()
Expand Down

0 comments on commit 731de6a

Please sign in to comment.