← Back to team overview

duplicity-team team mailing list archive

[Merge] lp:~ed.so/duplicity/debian.dav.mkdir into lp:duplicity

 

edso has proposed merging lp:~ed.so/duplicity/debian.dav.mkdir into lp:duplicity.

Requested reviews:
  duplicity-team (duplicity-team)

For more details, see:
https://code.launchpad.net/~ed.so/duplicity/debian.dav.mkdir/+merge/200133

tested and working
-- 
https://code.launchpad.net/~ed.so/duplicity/debian.dav.mkdir/+merge/200133
Your team duplicity-team is requested to review the proposed merge of lp:~ed.so/duplicity/debian.dav.mkdir into lp:duplicity.
=== modified file 'duplicity/backends/webdavbackend.py'
--- duplicity/backends/webdavbackend.py	2013-01-10 19:04:39 +0000
+++ duplicity/backends/webdavbackend.py	2013-12-28 16:42:41 +0000
@@ -272,12 +272,9 @@
             del self.headers['Depth']
             # if the target collection does not exist, create it.
             if response.status == 404:
-                response.close()
-                log.Info("Directory '%s' being created." % self.directory)
-                response = self.request("MKCOL", self.directory)
-                log.Info("WebDAV MKCOL status: %s %s" % (response.status, response.reason))
-                response.close()
-                # just created folder is so return empty
+                response.close() # otherwise next request fails with ResponseNotReady
+                self.makedir()
+                # just created an empty folder, so return empty
                 return []
             elif response.status in [200, 207]:
                 document = response.read()
@@ -301,6 +298,32 @@
         finally:
             if response: response.close()
 
+    def makedir(self):
+        """Make (nested) directories on the server."""
+        dirs = self.directory.split("/")
+        # url causes directory to start with /, but it might be given 
+        # with or without trailing / (which is required)
+        if dirs[-1] == '':
+            dirs=dirs[0:-1]
+        for i in range(1,len(dirs)):
+            d="/".join(dirs[0:i+1])+"/"
+       
+            self.close() # or we get previous request's data or exception       
+            self.headers['Depth'] = "1"
+            response = self.request("PROPFIND", d)
+            del self.headers['Depth']
+
+            log.Info("Checking existence dir %s: %d" % (d, response.status))
+
+            if response.status == 404:
+                log.Info("Creating missing directory %s" % d)
+                self.close() # or we get previous request's data or exception   
+
+                res = self.request("MKCOL", d)
+                if res.status != 201:
+                    raise BackendException("WebDAV MKCOL %s failed: %s %s" % (d,res.status,res.reason))
+                self.close()
+
     def __taste_href(self, href):
         """
         Internal helper to taste the given href node and, if


References