diff options
author | Lars Wirzenius <liw@liw.fi> | 2015-11-15 21:19:21 +0200 |
---|---|---|
committer | Lars Wirzenius <liw@liw.fi> | 2015-11-15 21:19:21 +0200 |
commit | 0c414b70f8c4e41c567b30305fee7e89dd019db3 (patch) | |
tree | 5dbca861ea2879921d520f516255c162eda7ba94 | |
parent | 21c451e436509ea41dd2fcf719cee000ea8f94a3 (diff) | |
download | obnam-0c414b70f8c4e41c567b30305fee7e89dd019db3.tar.gz |
Fix exclusion of subdirectory contents
This fixes a bug where --exclude-caches fails to correctly exclude
things. The problem was that scan_tree would scan through a
subdirectory, even when the directory itself should be excluded.
-rw-r--r-- | obnamlib/vfs.py | 17 |
1 files changed, 15 insertions, 2 deletions
diff --git a/obnamlib/vfs.py b/obnamlib/vfs.py index 05838bd3..eadf8b43 100644 --- a/obnamlib/vfs.py +++ b/obnamlib/vfs.py @@ -333,7 +333,8 @@ class VirtualFileSystem(object): if isinstance(metadata, BaseException): error_handler(filename, metadata) elif stat.S_ISDIR(metadata.st_mode) and not processed_dir: - items = process_dir(filename, metadata, items) + if ok(filename, metadata): + items = process_dir(filename, metadata, items) elif ok(filename, metadata): yield filename, metadata @@ -737,7 +738,7 @@ class VfsTests(object): # pragma: no cover self.assertEqual(self.fs.bytes_written, 3) def set_up_scan_tree(self): - self.dirs = ['foo', 'foo/bar', 'foobar'] + self.dirs = ['foo', 'foo/bar', 'foo/bar/subway', 'foobar'] self.dirs = [os.path.join(self.basepath, x) for x in self.dirs] for dirname in self.dirs: self.fs.mkdir(dirname) @@ -775,3 +776,15 @@ class VfsTests(object): # pragma: no cover result = list(self.fs.scan_tree(self.basepath, ok=ok)) pathnames = [pathname for pathname, _ in result] self.assertEqual(sorted(pathnames), sorted(self.dirs)) + + def test_scan_tree_filters_away_unwanted_subdirs(self): + def ok(pathname, st): + return not pathname.endswith('bar') + self.set_up_scan_tree() + result = list(self.fs.scan_tree(self.basepath, ok=ok)) + pathnames = [pathname for pathname, _ in result] + self.assertEqual( + sorted(pathnames), + sorted([self.basepath] + + [os.path.join(self.basepath, x) + for x in ['foo', 'symfoo']])) |