-def test_from_path_error():
- if os.geteuid() == 0 or detect_fakeroot():
- return
- tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
- try:
- path = tmpdir + '/foo'
- subprocess.call(['mkdir', path])
- m = metadata.from_path(path, archive_path=path, save_symlinks=True)
- WVPASSEQ(m.path, path)
- subprocess.call(['chmod', '000', path])
- metadata.from_path(path, archive_path=path, save_symlinks=True)
- errmsg = helpers.saved_errors[0] if helpers.saved_errors else ''
- WVPASS(errmsg.startswith('read Linux attr'))
- clear_errors()
- finally:
- subprocess.call(['rm', '-rf', tmpdir])
+def test_metadata_method():
+ with no_lingering_errors():
+ with test_tempdir('bup-tmetadata-') as tmpdir:
+ bup_dir = tmpdir + '/bup'
+ data_path = tmpdir + '/foo'
+ os.mkdir(data_path)
+ ex('touch', data_path + '/file')
+ ex('ln', '-s', 'file', data_path + '/symlink')
+ test_time1 = 13 * 1000000000
+ test_time2 = 42 * 1000000000
+ utime(data_path + '/file', (0, test_time1))
+ lutime(data_path + '/symlink', (0, 0))
+ utime(data_path, (0, test_time2))
+ ex(bup_path, '-d', bup_dir, 'init')
+ ex(bup_path, '-d', bup_dir, 'index', '-v', data_path)
+ ex(bup_path, '-d', bup_dir, 'save', '-tvvn', 'test', data_path)
+ git.check_repo_or_die(bup_dir)
+ repo = LocalRepo()
+ resolved = vfs.resolve(repo,
+ '/test/latest' + resolve_parent(data_path),
+ follow=False)
+ leaf_name, leaf_item = resolved[-1]
+ m = leaf_item.meta
+ WVPASS(m.mtime == test_time2)
+ WVPASS(leaf_name == 'foo')
+ contents = tuple(vfs.contents(repo, leaf_item))
+ WVPASS(len(contents) == 3)
+ WVPASSEQ(frozenset(name for name, item in contents),
+ frozenset(('.', 'file', 'symlink')))
+ for name, item in contents:
+ if name == 'file':
+ m = item.meta
+ WVPASS(m.mtime == test_time1)
+ elif name == 'symlink':
+ m = item.meta
+ WVPASSEQ(m.symlink_target, 'file')
+ WVPASSEQ(m.size, 4)
+ WVPASSEQ(m.mtime, 0)