Author: Alexander Zangerl <az@debian.org>
Subject: fix for #693521: nested mkcols

diff -urNad '--exclude=CVS' '--exclude=.svn' '--exclude=.git' '--exclude=.arch' '--exclude=.hg' '--exclude=_darcs' '--exclude=.bzr' duplicity-0.6.21~/duplicity/backends/webdavbackend.py duplicity-0.6.21/duplicity/backends/webdavbackend.py
--- duplicity-0.6.21~/duplicity/backends/webdavbackend.py	2013-01-24 00:35:56.000000000 +1000
+++ duplicity-0.6.21/duplicity/backends/webdavbackend.py	2013-05-24 11:29:07.278763182 +1000
@@ -272,11 +272,8 @@
             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()
+                response.close() # otherwise next request fails with ResponseNotReady
+                self.makedir()
                 # just created folder is so return empty
                 return []
             elif response.status in [200, 207]:
@@ -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
