from __future__ import print_function
from collections import namedtuple
+from errno import ELOOP, ENOTDIR
from io import BytesIO
from os import environ, symlink
from stat import S_IFDIR, S_IFREG, S_ISDIR, S_ISREG
save_time = 100000
save_time_str = strftime('%Y-%m-%d-%H%M%S', localtime(save_time))
os.mkdir(data_path)
+ os.mkdir(data_path + '/dir')
with open(data_path + '/file', 'w+') as tmpfile:
print('canary', file=tmpfile)
- symlink('file', data_path + '/symlink')
+ symlink('file', data_path + '/file-symlink')
+ symlink('dir', data_path + '/dir-symlink')
+ symlink('not-there', data_path + '/bad-symlink')
ex((bup_path, 'init'))
ex((bup_path, 'index', '-v', data_path))
ex((bup_path, 'save', '-d', str(save_time), '-tvvn', 'test',
tip_hash = exo(('git', 'show-ref', 'refs/heads/test'))[0]
tip_oidx = tip_hash.strip().split()[0]
tip_oid = tip_oidx.decode('hex')
- tip_meta = Metadata()
- tip_meta.mode = S_IFDIR | 0o755
- tip_meta.uid = tip_meta.gid = tip_meta.size = 0
- tip_meta.atime = tip_meta.mtime = tip_meta.ctime = save_time * 10**9
- test_revlist = vfs.RevList(meta=tip_meta, oid=tip_oid)
tip_tree_oidx = exo(('git', 'log', '--pretty=%T', '-n1',
tip_oidx))[0].strip()
tip_tree_oid = tip_tree_oidx.decode('hex')
tip_tree = tree_dict(repo, tip_tree_oid)
+ test_revlist = vfs.RevList(meta=S_IFDIR | 0o755, oid=tip_oid)
+ test_revlist_w_meta = vfs.RevList(meta=tip_tree['.'].meta,
+ oid=tip_oid)
+ expected_latest_item = vfs.Commit(meta=S_IFDIR | 0o755,
+ oid=tip_tree_oid,
+ coid=tip_oid)
+ expected_test_tag_item = expected_latest_item
wvstart('resolve: /')
res = resolve(repo, '/')
('.tag', vfs._tags),
('test', test_revlist)]),
root_content)
+ for path in ('//', '/.', '/./', '/..', '/../',
+ '/test/latest/dir/../../..',
+ '/test/latest/dir/../../../',
+ '/test/latest/dir/../../../.',
+ '/test/latest/dir/../../..//',
+ '/test//latest/dir/../../..',
+ '/test/./latest/dir/../../..',
+ '/test/././latest/dir/../../..',
+ '/test/.//./latest/dir/../../..',
+ '/test//.//.//latest/dir/../../..'
+ '/test//./latest/dir/../../..'):
+ wvstart('resolve: ' + path)
+ res = resolve(repo, path)
+ wvpasseq((('', vfs._root),), res)
wvstart('resolve: /.tag')
res = resolve(repo, '/.tag')
ignore, tag_item = res[1]
tag_content = frozenset(vfs.contents(repo, tag_item))
wvpasseq(frozenset([('.', tag_item),
- ('test-tag', test_revlist)]),
+ ('test-tag', expected_test_tag_item)]),
tag_content)
wvstart('resolve: /test')
wvpasseq((('', vfs._root), ('test', test_revlist)), res)
ignore, test_item = res[1]
test_content = frozenset(vfs.contents(repo, test_item))
- expected_latest_item = vfs.Item(meta=S_IFDIR | 0o755,
- oid=tip_tree_oid)
- wvpasseq(frozenset([('.', test_revlist),
+ wvpasseq(frozenset([('.', test_revlist_w_meta),
(save_time_str, expected_latest_item),
('latest', expected_latest_item)]),
test_content)
wvstart('resolve: /test/latest')
res = resolve(repo, '/test/latest')
wvpasseq(3, len(res))
- expected_latest_item_w_meta = vfs.Item(meta=tip_tree['.'].meta,
- oid=tip_tree_oid)
+ expected_latest_item_w_meta = vfs.Commit(meta=tip_tree['.'].meta,
+ oid=tip_tree_oid,
+ coid=tip_oid)
expected = (('', vfs._root),
('test', test_revlist),
('latest', expected_latest_item_w_meta))
latest_content = frozenset(vfs.contents(repo, latest_item))
expected = frozenset((x.name, vfs.Item(oid=x.oid, meta=x.meta))
for x in (tip_tree[name]
- for name in ('.', 'file',
- 'symlink')))
+ for name in ('.',
+ 'bad-symlink',
+ 'dir',
+ 'dir-symlink',
+ 'file',
+ 'file-symlink')))
wvpasseq(expected, latest_content)
- wvstart('resolve: /test/latest/foo')
+ wvstart('resolve: /test/latest/file')
res = resolve(repo, '/test/latest/file')
wvpasseq(4, len(res))
expected_file_item_w_meta = vfs.Item(meta=tip_tree['file'].meta,
('file', expected_file_item_w_meta))
wvpasseq(expected, res)
- wvstart('resolve: /test/latest/symlink')
- res = resolve(repo, '/test/latest/symlink')
+ wvstart('resolve: /test/latest/bad-symlink')
+ res = resolve(repo, '/test/latest/bad-symlink')
+ wvpasseq(4, len(res))
+ expected = (('', vfs._root),
+ ('test', test_revlist),
+ ('latest', expected_latest_item_w_meta),
+ ('not-there', None))
+ wvpasseq(expected, res)
+
+ wvstart('lresolve: /test/latest/bad-symlink')
+ res = lresolve(repo, '/test/latest/bad-symlink')
+ wvpasseq(4, len(res))
+ bad_symlink_value = tip_tree['bad-symlink']
+ expected_bad_symlink_item_w_meta = vfs.Item(meta=bad_symlink_value.meta,
+ oid=bad_symlink_value.oid)
+ expected = (('', vfs._root),
+ ('test', test_revlist),
+ ('latest', expected_latest_item_w_meta),
+ ('bad-symlink', expected_bad_symlink_item_w_meta))
+ wvpasseq(expected, res)
+
+ wvstart('resolve: /test/latest/file-symlink')
+ res = resolve(repo, '/test/latest/file-symlink')
wvpasseq(4, len(res))
expected = (('', vfs._root),
('test', test_revlist),
('file', expected_file_item_w_meta))
wvpasseq(expected, res)
- wvstart('lresolve: /test/latest/symlink')
- res = lresolve(repo, '/test/latest/symlink')
+ wvstart('lresolve: /test/latest/file-symlink')
+ res = lresolve(repo, '/test/latest/file-symlink')
wvpasseq(4, len(res))
- symlink_value = tip_tree['symlink']
- expected_symlink_item_w_meta = vfs.Item(meta=symlink_value.meta,
- oid=symlink_value.oid)
+ file_symlink_value = tip_tree['file-symlink']
+ expected_file_symlink_item_w_meta = vfs.Item(meta=file_symlink_value.meta,
+ oid=file_symlink_value.oid)
expected = (('', vfs._root),
('test', test_revlist),
('latest', expected_latest_item_w_meta),
- ('symlink', expected_symlink_item_w_meta))
+ ('file-symlink', expected_file_symlink_item_w_meta))
wvpasseq(expected, res)
wvstart('resolve: /test/latest/missing')
wvpasseq('missing', name)
wvpass(item is None)
+ for path in ('/test/latest/file/',
+ '/test/latest/file/.',
+ '/test/latest/file/..',
+ '/test/latest/file/../',
+ '/test/latest/file/../.',
+ '/test/latest/file/../..',
+ '/test/latest/file/foo'):
+ wvstart('resolve: ' + path)
+ try:
+ resolve(repo, path)
+ except vfs.IOError as res_ex:
+ wvpasseq(ENOTDIR, res_ex.errno)
+ wvpasseq(['', 'test', 'latest', 'file'],
+ [name for name, item in res_ex.terminus])
+
+ for path in ('/test/latest/file-symlink/',
+ '/test/latest/file-symlink/.',
+ '/test/latest/file-symlink/..',
+ '/test/latest/file-symlink/../',
+ '/test/latest/file-symlink/../.',
+ '/test/latest/file-symlink/../..'):
+ wvstart('lresolve: ' + path)
+ try:
+ lresolve(repo, path)
+ except vfs.IOError as res_ex:
+ wvpasseq(ENOTDIR, res_ex.errno)
+ wvpasseq(['', 'test', 'latest', 'file'],
+ [name for name, item in res_ex.terminus])
+
+ wvstart('resolve: non-directory parent')
+ file_res = resolve(repo, '/test/latest/file')
+ try:
+ resolve(repo, 'foo', parent=file_res)
+ except vfs.IOError as res_ex:
+ wvpasseq(ENOTDIR, res_ex.errno)
+ wvpasseq(None, res_ex.terminus)
+
+ wvstart('lresolve: /test/latest/dir-symlink')
+ res = lresolve(repo, '/test/latest/dir-symlink')
+ wvpasseq(4, len(res))
+ dir_symlink_value = tip_tree['dir-symlink']
+ expected_dir_symlink_item_w_meta = vfs.Item(meta=dir_symlink_value.meta,
+ oid=dir_symlink_value.oid)
+ expected = (('', vfs._root),
+ ('test', test_revlist),
+ ('latest', expected_latest_item_w_meta),
+ ('dir-symlink', expected_dir_symlink_item_w_meta))
+ wvpasseq(expected, res)
+
+ dir_value = tip_tree['dir']
+ expected_dir_item = vfs.Item(oid=dir_value.oid,
+ meta=tree_dict(repo, dir_value.oid)['.'].meta)
+ expected = (('', vfs._root),
+ ('test', test_revlist),
+ ('latest', expected_latest_item_w_meta),
+ ('dir', expected_dir_item))
+ for resname, resolver in (('resolve', resolve),
+ ('lresolve', lresolve)):
+ for path in ('/test/latest/dir-symlink/',
+ '/test/latest/dir-symlink/.'):
+ wvstart(resname + ': ' + path)
+ res = resolver(repo, path)
+ wvpasseq(4, len(res))
+ wvpasseq(expected, res)
+ wvstart('resolve: /test/latest/dir-symlink')
+ res = resolve(repo, path)
+ wvpasseq(4, len(res))
+ wvpasseq(expected, res)
+
@wvtest
def test_resolve_loop():
with no_lingering_errors():
ex((bup_path, 'index', '-v', data_path))
ex((bup_path, 'save', '-d', '100000', '-tvvn', 'test', '--strip',
data_path))
- wvexcept(vfs.Loop, resolve, repo, '/test/latest/loop')
+ try:
+ resolve(repo, '/test/latest/loop')
+ except vfs.IOError as res_ex:
+ wvpasseq(ELOOP, res_ex.errno)
+ wvpasseq(['', 'test', 'latest', 'loop'],
+ [name for name, item in res_ex.terminus])
@wvtest
def test_contents_with_mismatched_bupm_git_ordering():
name, revlist = res[-1]
wvpasseq('test', name)
wvpasseq(('.',
- '1970-01-02-034640-10',
- '1970-01-02-034640-09',
- '1970-01-02-034640-08',
- '1970-01-02-034640-07',
- '1970-01-02-034640-06',
- '1970-01-02-034640-05',
- '1970-01-02-034640-04',
- '1970-01-02-034640-03',
- '1970-01-02-034640-02',
- '1970-01-02-034640-01',
'1970-01-02-034640-00',
+ '1970-01-02-034640-01',
+ '1970-01-02-034640-02',
+ '1970-01-02-034640-03',
+ '1970-01-02-034640-04',
+ '1970-01-02-034640-05',
+ '1970-01-02-034640-06',
+ '1970-01-02-034640-07',
+ '1970-01-02-034640-08',
+ '1970-01-02-034640-09',
+ '1970-01-02-034640-10',
'latest'),
- tuple(x[0] for x in vfs.contents(repo, revlist)))
+ tuple(sorted(x[0] for x in vfs.contents(repo, revlist))))
# FIXME: add tests for the want_meta=False cases.