From: Rob Browning Date: Sat, 25 Nov 2017 17:10:03 +0000 (-0600) Subject: vfs2._resolve_path: require parent to be a path sequence X-Git-Tag: 0.30~153 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=cd9d0500b375dd70347d5b780a90a975b012baf7 vfs2._resolve_path: require parent to be a path sequence Require an actual path sequence for the parent since it provides the context for the resolution of the path (with respect to relative paths, symlinks containing .., etc.). Signed-off-by: Rob Browning Tested-by: Rob Browning --- diff --git a/lib/bup/vfs2.py b/lib/bup/vfs2.py index 7cfa928..4408885 100644 --- a/lib/bup/vfs2.py +++ b/lib/bup/vfs2.py @@ -211,6 +211,7 @@ Chunky = namedtuple('Chunky', ('meta', 'oid')) Root = namedtuple('Root', ('meta')) Tags = namedtuple('Tags', ('meta')) RevList = namedtuple('RevList', ('meta', 'oid')) +item_types = (Item, Chunky, Root, Tags, RevList) _root = Root(meta=default_dir_mode) _tags = Tags(meta=default_dir_mode) @@ -664,20 +665,27 @@ def contents(repo, item, names=None, want_meta=True): yield x def _resolve_path(repo, path, parent=None, want_meta=True, deref=False): + global _root assert repo assert len(path) - global _root + if parent: + for x in parent: + assert len(x) == 2 + assert type(x[0]) in (bytes, str) + assert type(x[1]) in item_types + assert parent[0][1] == _root future = _decompose_path(path) - past = [] if path.startswith('/'): - assert(not parent) - past = [('', _root)] if future == ['']: # path was effectively '/' - return tuple(past) - if not past and not parent: + return (('', _root),) past = [('', _root)] - if parent: - past = [parent] + else: + if parent: + past = list(parent) + else: + past = [('', _root)] + if not future: # e.g. if path was effectively '.' + return tuple(past) hops = 0 result = None while True: @@ -762,11 +770,11 @@ def resolve(repo, path, parent=None, want_meta=True): Currently, a path ending in '/' will still resolve if it exists, even if not a directory. The parent, if specified, must be a - (name, item) tuple, and will provide the starting point for the - resolution of the path. Currently, the path must be relative when - a parent is provided. The result may include parent directly, so - it must not be modified later. If this is a concern, pass in - copy_item(parent) instead. + sequence of (name, item) tuples, and will provide the starting + point for the resolution of the path. The result may include + elements of parent directly, so they must not be modified later. + If this is a concern, pass in "name, copy_item(item) for + name, item in parent" instead. When want_meta is true, detailed metadata will be included in each result item if it's avaiable, otherwise item.meta will be an