1683
1683
def children(self):
1684
1684
"""Access the list of children of this inventory.
1686
Currently causes a full-load of all the children; a more sophisticated
1687
proxy object is planned.
1686
With a parent_id_basename_to_file_id index, loads all the children,
1687
without loads the entire index. Without is bad. A more sophisticated
1688
proxy object might be nice, to allow partial loading of children as
1689
well when specific names are accessed. (So path traversal can be
1690
written in the obvious way but not examine siblings.).
1689
1692
if self._children is not None:
1690
1693
return self._children
1694
if self._chk_inventory.parent_id_basename_to_file_id is None:
1695
# Slow path - read the entire inventory looking for kids.
1697
for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
1698
entry = self._chk_inventory._bytes_to_entry(bytes)
1699
if entry.parent_id == self.file_id:
1700
result[entry.name] = entry
1701
self._children = result
1704
# XXX: Todo - use proxy objects for the children rather than loading
1705
# all when the attribute is referenced.
1706
parent_id_index = self._chk_inventory.parent_id_basename_to_file_id
1708
for (parent_id, name_utf8), file_id in parent_id_index.iteritems(
1709
key_filter=[(self.file_id,)]):
1710
child_ids.add((file_id,))
1692
1711
# populate; todo: do by name
1693
for file_id, bytes in self._chk_inventory.id_to_entry.iteritems():
1712
id_to_entry = self._chk_inventory.id_to_entry
1713
for file_id, bytes in id_to_entry.iteritems(child_ids):
1694
1714
entry = self._chk_inventory._bytes_to_entry(bytes)
1695
if entry.parent_id == self.file_id:
1696
result[entry.name] = entry
1715
result[entry.name] = entry
1697
1716
self._children = result