commit 9a132872dd12e68edc0c6153213da06e20163c32 Author: Dmitry Nezhevenko Date: Mon May 30 10:14:36 2016 +0300 dpbx: upload last chunk with files_upload_session_finish to avoid extra request diff --git a/duplicity/backends/dpbxbackend.py b/duplicity/backends/dpbxbackend.py index a5c53ef..46666a5 100644 --- a/duplicity/backends/dpbxbackend.py +++ b/duplicity/backends/dpbxbackend.py @@ -190,10 +190,11 @@ class DPBXBackend(duplicity.backend.Backend): requested_offset = None current_chunk_size = DPBX_UPLOAD_CHUNK_SIZE retry_number = globals.num_retries + is_eof = False # We're doing our own error handling and retrying logic because # we can benefit from Dpbx chunked upload and retry only failed chunk - while (f.tell() < file_size) or not res_metadata: + while not is_eof or not res_metadata: try: if requested_offset is not None: upload_cursor.offset = requested_offset @@ -202,12 +203,17 @@ class DPBXBackend(duplicity.backend.Backend): f.seek(upload_cursor.offset) buf = f.read(current_chunk_size) + is_eof = f.tell() >= file_size + if not is_eof and len(buf) == 0: + continue + # reset temporary status variables requested_offset = None current_chunk_size = DPBX_UPLOAD_CHUNK_SIZE retry_number = globals.num_retries - if len(buf) != 0: + if not is_eof: + assert len(buf) != 0 log.Debug('dpbx,files_upload_sesssion_append([%d bytes], offset=%d)' % (len(buf), upload_cursor.offset)) self.api_client.files_upload_session_append(buf, upload_cursor.session_id, upload_cursor.offset) else: