|
9 | 9 | import tempfile |
10 | 10 | import time |
11 | 11 | import unittest |
| 12 | +import itertools |
12 | 13 | from hashlib import sha256 |
13 | 14 | from attic import xattr |
14 | 15 | from attic.archive import Archive, ChunkBuffer |
@@ -59,6 +60,9 @@ def __exit__(self, *args, **kw): |
59 | 60 | if v is not None: |
60 | 61 | os.environ[k] = v |
61 | 62 |
|
| 63 | +def listdir_recursive(dirname): |
| 64 | + return itertools.chain(*[[os.path.normpath(os.path.join(dirpath, f)) for f in filenames] |
| 65 | + for dirpath, dirnames, filenames in os.walk(dirname)]) |
62 | 66 |
|
63 | 67 | class ArchiverTestCaseBase(AtticTestCase): |
64 | 68 |
|
@@ -262,6 +266,27 @@ def test_exclude_caches(self): |
262 | 266 | self.assert_equal(sorted(os.listdir('output/input')), ['cache2', 'file1']) |
263 | 267 | self.assert_equal(sorted(os.listdir('output/input/cache2')), ['CACHEDIR.TAG']) |
264 | 268 |
|
| 269 | + def test_files_from(self): |
| 270 | + self._test_files_from_option(delim=b'\n', option='--files-from') |
| 271 | + |
| 272 | + def test_files_from0(self): |
| 273 | + self._test_files_from_option(delim=b'\0', option='--files-from0') |
| 274 | + |
| 275 | + def _test_files_from_option(self, *, delim, option): |
| 276 | + self.attic('init', self.repository_location) |
| 277 | + for filename in ['file1', 'non-listed/file', 'listed/file']: |
| 278 | + self.create_regular_file(filename, size=1024 * 80) |
| 279 | + listed_files = sorted(['file1', 'listed/file']) |
| 280 | + self.create_regular_file('filelist', |
| 281 | + contents=delim.join([os.path.join('input', f).encode('ascii') |
| 282 | + for f in listed_files])) |
| 283 | + self.attic('create', option + '=input/filelist', self.repository_location + '::test') |
| 284 | + with changedir('output'): |
| 285 | + self.attic('extract', self.repository_location + '::test') |
| 286 | + with changedir('output/input'): |
| 287 | + present_files = sorted(listdir_recursive('.')) |
| 288 | + self.assert_equal(present_files, listed_files) |
| 289 | + |
265 | 290 | def test_path_normalization(self): |
266 | 291 | self.attic('init', self.repository_location) |
267 | 292 | self.create_regular_file('dir1/dir2/file', size=1024 * 80) |
|
0 commit comments