← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~townsend/duplicity/fix-1161599 into lp:duplicity

 

Christopher Townsend has proposed merging lp:~townsend/duplicity/fix-1161599 into lp:duplicity.

Requested reviews:
  duplicity-team (duplicity-team)
Related bugs:
  Bug #1161599 in Duplicity: "Backup to Ubuntu one failed, after 5 attempts status 400 bad request"
  https://bugs.launchpad.net/duplicity/+bug/1161599

For more details, see:
https://code.launchpad.net/~townsend/duplicity/fix-1161599/+merge/159849

Transient socket or HTTP errors will cause a retry of the PUT for a backup.  This would then lead to 400 Bad Request errors from the server.  This MP:

* Fixes the case where the file pointer to the backup file was not being set back to the beginning of the file when an error occurs. This causes subsequent retries to fail with 400 Bad Request errors from the server. This is due to a change in revno. 901 where a file handle is used instead of a bytearray.
* Fixes the removal of Content-Length from the header in revno. 901. Content-Length is required according to the Ubuntu One API documentation.
-- 
https://code.launchpad.net/~townsend/duplicity/fix-1161599/+merge/159849
Your team duplicity-team is requested to review the proposed merge of lp:~townsend/duplicity/fix-1161599 into lp:duplicity.
=== modified file 'duplicity/backends/u1backend.py'
--- duplicity/backends/u1backend.py	2012-12-25 16:49:33 +0000
+++ duplicity/backends/u1backend.py	2013-04-19 15:56:39 +0000
@@ -84,6 +84,7 @@
                           % duplicity.util.exception_traceback())
                 if n == globals.num_retries:
                     log.FatalError("Giving up on request after %d attempts, last exception %s" % (n,e))
+                body.seek(0) # Go to the beginning of the file for the retry
                 time.sleep(30)
                 continue
 
@@ -105,6 +106,8 @@
                 ecode = log.ErrorCode.backend_no_space
             elif numcode == 404:
                 ecode = log.ErrorCode.backend_not_found
+ 
+            body.seek(0) # Go to the beginning of the file for the retry
 
             if n < globals.num_retries:
                 time.sleep(30)
@@ -207,10 +210,12 @@
         remote_full = self.content_base + self.quote(content['content_path'])
         log.Info("uploading file %s to location %s" % (remote_filename, remote_full))
 
+        size = os.path.getsize(source_path.name)
         fh=open(source_path.name,'rb')
 
         content_type = 'application/octet-stream'
-        headers = {"Content-Type": content_type}
+        headers = {"Content-Length": str(size),
+                   "Content-Type": content_type}
         resp, content = self.client.request(remote_full,
                                             method="PUT",
                                             body=fh,