4 from bup.helpers import should_rx_exclude_path, debug1
5 import bup.xstat as xstat
9 O_LARGEFILE = os.O_LARGEFILE
10 except AttributeError:
13 O_NOFOLLOW = os.O_NOFOLLOW
14 except AttributeError:
18 # the use of fchdir() and lstat() is for two reasons:
19 # - help out the kernel by not making it repeatedly look up the absolute path
20 # - avoid race conditions caused by doing listdir() on a changing symlink
22 def __init__(self, path):
24 self.fd = os.open(path, os.O_RDONLY|O_LARGEFILE|O_NOFOLLOW|os.O_NDELAY)
36 return xstat.fstat(self.fd)
39 _IFMT = stat.S_IFMT(0xffffffff) # avoid function call in inner loop
42 for n in os.listdir('.'):
46 add_error(Exception('%s: %s' % (resolve_parent(n), str(e))))
48 if (st.st_mode & _IFMT) == stat.S_IFDIR:
55 def _recursive_dirlist(prepend, xdev, bup_dir=None,
58 for (name,pst) in _dirlist():
61 if os.path.normpath(path) in excluded_paths:
62 debug1('Skipping %r: excluded.\n' % path)
64 if exclude_rxs and should_rx_exclude_path(path, exclude_rxs):
66 if name.endswith('/'):
68 if os.path.normpath(path) == bup_dir:
69 debug1('Skipping BUP_DIR.\n')
71 if xdev != None and pst.st_dev != xdev:
72 debug1('Skipping contents of %r: different filesystem.\n' % path)
77 add_error('%s: %s' % (prepend, e))
79 for i in _recursive_dirlist(prepend=prepend+name, xdev=xdev,
81 excluded_paths=excluded_paths,
82 exclude_rxs=exclude_rxs):
88 def recursive_dirlist(paths, xdev, bup_dir=None, excluded_paths=None,
90 startdir = OsFile('.')
92 assert(type(paths) != type(''))
95 pst = xstat.lstat(path)
96 if stat.S_ISLNK(pst.st_mode):
100 add_error('recursive_dirlist: %s' % e)
112 if stat.S_ISDIR(pst.st_mode):
114 prepend = os.path.join(path, '')
115 for i in _recursive_dirlist(prepend=prepend, xdev=xdev,
117 excluded_paths=excluded_paths,
118 exclude_rxs=exclude_rxs):