fix strip_base_dir argument for DeltaTar._recursive_walk_dir: check for os.sep
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 13:28:09 +0000 (15:28 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 13:28:09 +0000 (15:28 +0200)
deltatar/deltatar.py

index 682667a..b258690 100644 (file)
@@ -359,17 +359,20 @@ class DeltaTar(object):
 
         return match
 
-    def _recursive_walk_dir(self, source_path, strip_base_dir = False):
+    def _recursive_walk_dir(self, source_path, keep_base_dir=False):
         '''
         Walk a directory recursively, yielding each file/directory
         '''
 
-        queue = [source_path]
+        source_path = source_path.rstrip(os.sep)
 
-        if strip_base_dir:
-            beginning_size = len(source_path)
-        else:
+        if keep_base_dir:
             beginning_size = 0
+        else:
+            beginning_size = len(source_path) + 1       # +1 for os.sep
+
+        queue = [source_path]
+
         while queue:
             cur_path = queue.pop(0)
 
@@ -1438,7 +1441,7 @@ class RestoreHelper(object):
             return
 
         # to preserve parent directory mtime, we save it
-        parent_dir = os.path.dirname(path)
+        parent_dir = os.path.dirname(path) or os.getcwd()
         parent_dir_mtime = int(os.stat(parent_dir).st_mtime)
 
         if os.path.isdir(path) and not os.path.islink(path):
@@ -1470,7 +1473,7 @@ class RestoreHelper(object):
         upath = self._deltatar.unprefixed(path)
 
         # to preserve parent directory mtime, we save it
-        parent_dir = os.path.dirname(upath)
+        parent_dir = os.path.dirname(upath) or os.getcwd()
         if not os.path.exists(parent_dir):
             os.makedirs(parent_dir)
         parent_dir_mtime = int(os.stat(parent_dir).st_mtime)