]> arthur.barton.de Git - bup.git/blobdiff - lib/bup/drecurse.py
helpers: rename realpath to resolve_parent
[bup.git] / lib / bup / drecurse.py
index 5d497709531350176465d853b209376aa78e1344..90b7f26de4bf6316230c68ed49304a5d73e8c927 100644 (file)
@@ -39,8 +39,8 @@ def _dirlist():
     for n in os.listdir('.'):
         try:
             st = xstat.lstat(n)
-        except OSError, e:
-            add_error(Exception('%s: %s' % (realpath(n), str(e))))
+        except OSError as e:
+            add_error(Exception('%s: %s' % (resolve_parent(n), str(e))))
             continue
         if (st.st_mode & _IFMT) == stat.S_IFDIR:
             n += '/'
@@ -49,34 +49,41 @@ def _dirlist():
     return l
 
 
-def _recursive_dirlist(prepend, xdev, bup_dir=None, excluded_paths=None):
+def _recursive_dirlist(prepend, xdev, bup_dir=None,
+                       excluded_paths=None,
+                       exclude_rxs=None):
     for (name,pst) in _dirlist():
+        path = prepend + name
         if excluded_paths:
-            if os.path.normpath(prepend+name) in excluded_paths:
-                debug1('Skipping %r: excluded.\n' % (prepend+name))
+            if os.path.normpath(path) in excluded_paths:
+                debug1('Skipping %r: excluded.\n' % path)
                 continue
+        if exclude_rxs and should_rx_exclude_path(path, exclude_rxs):
+            continue
         if name.endswith('/'):
-            if xdev != None and pst.st_dev != xdev:
-                debug1('Skipping %r: different filesystem.\n' % (prepend+name))
-                continue
             if bup_dir != None:
-                if os.path.normpath(prepend+name) == bup_dir:
+                if os.path.normpath(path) == bup_dir:
                     debug1('Skipping BUP_DIR.\n')
                     continue
-            try:
-                OsFile(name).fchdir()
-            except OSError, e:
-                add_error('%s: %s' % (prepend, e))
+            if xdev != None and pst.st_dev != xdev:
+                debug1('Skipping contents of %r: different filesystem.\n' % path)
             else:
-                for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
-                                            bup_dir=bup_dir,
-                                            excluded_paths=excluded_paths):
-                    yield i
-                os.chdir('..')
-        yield (prepend + name, pst)
+                try:
+                    OsFile(name).fchdir()
+                except OSError as e:
+                    add_error('%s: %s' % (prepend, e))
+                else:
+                    for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
+                                                bup_dir=bup_dir,
+                                                excluded_paths=excluded_paths,
+                                                exclude_rxs=exclude_rxs):
+                        yield i
+                    os.chdir('..')
+        yield (path, pst)
 
 
-def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
+def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
+                      exclude_rxs=None):
     startdir = OsFile('.')
     try:
         assert(type(paths) != type(''))
@@ -86,12 +93,12 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
                 if stat.S_ISLNK(pst.st_mode):
                     yield (path, pst)
                     continue
-            except OSError, e:
+            except OSError as e:
                 add_error('recursive_dirlist: %s' % e)
                 continue
             try:
                 pfile = OsFile(path)
-            except OSError, e:
+            except OSError as e:
                 add_error(e)
                 continue
             pst = pfile.stat()
@@ -104,7 +111,8 @@ def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None):
                 prepend = os.path.join(path, '')
                 for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
                                             bup_dir=bup_dir,
-                                            excluded_paths=excluded_paths):
+                                            excluded_paths=excluded_paths,
+                                            exclude_rxs=exclude_rxs):
                     yield i
                 startdir.fchdir()
             else: