From: Christian Herdtweck Date: Fri, 17 Jun 2016 13:28:09 +0000 (+0200) Subject: fix strip_base_dir argument for DeltaTar._recursive_walk_dir: check for os.sep X-Git-Tag: v2.2~28 X-Git-Url: http://developer.intra2net.com/git/?a=commitdiff_plain;h=283fbd5e6d53b9896edf71c707b9e5575f6ae9e5;p=python-delta-tar fix strip_base_dir argument for DeltaTar._recursive_walk_dir: check for os.sep --- diff --git a/deltatar/deltatar.py b/deltatar/deltatar.py index 682667a..b258690 100644 --- a/deltatar/deltatar.py +++ b/deltatar/deltatar.py @@ -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)