simplify DeltaTar._recursive_walk_dir
authorChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 09:59:27 +0000 (11:59 +0200)
committerChristian Herdtweck <christian.herdtweck@intra2net.com>
Fri, 17 Jun 2016 09:59:27 +0000 (11:59 +0200)
(had called os.path.isdir and filter_path twice on each file directly
 after another)

deltatar/deltatar.py

index 9bd6927..682667a 100644 (file)
@@ -364,20 +364,6 @@ class DeltaTar(object):
         Walk a directory recursively, yielding each file/directory
         '''
 
-        def walk_dir(dir_path):
-            '''
-            Walk a directory, yielding each file/directory
-            '''
-            for filename in sorted(os.listdir(dir_path)):
-                file_path = os.path.join(dir_path, filename)
-                is_dir = os.path.isdir(file_path)
-                if self.filter_path(file_path, source_path, is_dir) == NO_MATCH:
-                    continue
-                if not os.access(file_path, os.R_OK):
-                    self.logger.warn('Error accessing possibly locked file %s' % file_path)
-                    continue
-                yield file_path
-
         queue = [source_path]
 
         if strip_base_dir:
@@ -391,9 +377,15 @@ class DeltaTar(object):
             if not os.path.exists(cur_path):
                 continue
 
-            for child in walk_dir(cur_path):
+            for filename in sorted(os.listdir(cur_path)):
+                child = os.path.join(cur_path, filename)
                 is_dir = os.path.isdir(child)
                 status = self.filter_path(child, source_path, is_dir)
+                if status == NO_MATCH:
+                    continue
+                if not os.access(child, os.R_OK):
+                    self.logger.warn('Error accessing possibly locked file %s' % child)
+                    continue
 
                 if status == MATCH:
                     yield child[beginning_size:]