- tmpdir = tempfile.mkdtemp(prefix='bup-tmetadata-')
- try:
- 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)
- top = vfs.RefList(None)
- n = top.lresolve('/test/latest' + realpath(data_path))
- m = n.metadata()
- WVPASS(m.mtime == test_time2)
- WVPASS(len(n.subs()) == 2)
- WVPASS(n.name == 'foo')
- WVPASS(set([x.name for x in n.subs()]) == set(['file', 'symlink']))
- for sub in n:
- if sub.name == 'file':
- m = sub.metadata()
- WVPASS(m.mtime == test_time1)
- elif sub.name == 'symlink':
- m = sub.metadata()
- WVPASS(m.mtime == 0)
- finally:
- subprocess.call(['rm', '-rf', tmpdir])
+ 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.lresolve(repo,
+ '/test/latest' + resolve_parent(data_path))
+ 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)