def augment_item_meta(repo, item, include_size=False): """Ensure item has a Metadata instance for item.meta. If item.meta is currently a mode, replace it with a compatible "fake" Metadata instance. If include_size is true, ensure item.meta.size is correct, computing it if needed. If item.meta is a Metadata instance, this call may modify it in place or replace it. """ # If we actually had parallelism, we'd need locking... assert repo m = item.meta if isinstance(m, Metadata): if include_size and m.size is None: m.size = _compute_item_size(repo, item) return item._replace(meta=m) return item # m is mode meta = Metadata() meta.mode = m meta.uid = meta.gid = None meta.atime = meta.mtime = meta.ctime = 0 if S_ISLNK(m): if isinstance(item, FakeLink): target = item.target else: target = _readlink(repo, item.oid) meta.symlink_target = target meta.size = len(target) elif include_size: meta.size = _compute_item_size(repo, item) return item._replace(meta=meta)
def augment_item_meta(repo, item, include_size=False): """Ensure item has a Metadata instance for item.meta. If item.meta is currently a mode, replace it with a compatible "fake" Metadata instance. If include_size is true, ensure item.meta.size is correct, computing it if needed. If item.meta is a Metadata instance, this call may modify it in place or replace it. """ # If we actually had parallelism, we'd need locking... assert repo m = item.meta if isinstance(m, Metadata): if include_size and m.size is None: m.size = _compute_item_size(repo, item) return item._replace(meta=m) return item # m is mode meta = Metadata() meta.mode = m meta.uid = meta.gid = meta.atime = meta.mtime = meta.ctime = 0 if S_ISLNK(m): if isinstance(item, FakeLink): target = item.target else: target = _readlink(repo, item.oid) meta.symlink_target = target meta.size = len(target) elif include_size: meta.size = _compute_item_size(repo, item) return item._replace(meta=meta)
def test_resolve(): with no_lingering_errors(): with test_tempdir('bup-tvfs-') as tmpdir: resolve = vfs.resolve lresolve = vfs.lresolve bup_dir = tmpdir + '/bup' environ['GIT_DIR'] = bup_dir environ['BUP_DIR'] = bup_dir git.repodir = bup_dir data_path = tmpdir + '/src' save_time = 100000 save_time_str = strftime('%Y-%m-%d-%H%M%S', localtime(save_time)) os.mkdir(data_path) with open(data_path + '/file', 'w+') as tmpfile: print('canary', file=tmpfile) symlink('file', data_path + '/symlink') ex((bup_path, 'init')) ex((bup_path, 'index', '-v', data_path)) ex((bup_path, 'save', '-d', str(save_time), '-tvvn', 'test', '--strip', data_path)) ex((bup_path, 'tag', 'test-tag', 'test')) repo = LocalRepo() 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) wvstart('resolve: /') res = resolve(repo, '/') wvpasseq(1, len(res)) wvpasseq((('', vfs._root), ), res) ignore, root_item = res[0] root_content = frozenset(vfs.contents(repo, root_item)) wvpasseq( frozenset([('.', root_item), ('.tag', vfs._tags), ('test', test_revlist)]), root_content) wvstart('resolve: /.tag') res = resolve(repo, '/.tag') wvpasseq(2, len(res)) wvpasseq((('', vfs._root), ('.tag', vfs._tags)), res) ignore, tag_item = res[1] tag_content = frozenset(vfs.contents(repo, tag_item)) wvpasseq(frozenset([('.', tag_item), ('test-tag', test_revlist)]), tag_content) wvstart('resolve: /test') res = resolve(repo, '/test') wvpasseq(2, len(res)) 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), (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 = (('', vfs._root), ('test', test_revlist), ('latest', expected_latest_item_w_meta)) wvpasseq(expected, res) ignore, latest_item = res[2] 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'))) wvpasseq(expected, latest_content) wvstart('resolve: /test/latest/foo') res = resolve(repo, '/test/latest/file') wvpasseq(4, len(res)) expected_file_item_w_meta = vfs.Item(meta=tip_tree['file'].meta, oid=tip_tree['file'].oid) expected = (('', vfs._root), ('test', test_revlist), ('latest', expected_latest_item_w_meta), ('file', expected_file_item_w_meta)) wvpasseq(expected, res) wvstart('resolve: /test/latest/symlink') res = resolve(repo, '/test/latest/symlink') wvpasseq(4, len(res)) expected = (('', vfs._root), ('test', test_revlist), ('latest', expected_latest_item_w_meta), ('file', expected_file_item_w_meta)) wvpasseq(expected, res) wvstart('lresolve: /test/latest/symlink') res = lresolve(repo, '/test/latest/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) expected = (('', vfs._root), ('test', test_revlist), ('latest', expected_latest_item_w_meta), ('symlink', expected_symlink_item_w_meta)) wvpasseq(expected, res) wvstart('resolve: /test/latest/missing') res = resolve(repo, '/test/latest/missing') wvpasseq(4, len(res)) name, item = res[-1] wvpasseq('missing', name) wvpass(item is None)
def _commit_meta_from_auth_sec(author_sec): m = Metadata() m.mode = default_dir_mode m.uid = m.gid = m.size = 0 m.atime = m.mtime = m.ctime = author_sec * 10**9 return m