Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/in_memory.py
Show First 20 Lines • Show All 312 Lines • ▼ Show 20 Lines | def _join_dentry_to_content(self, dentry): | ||||
ret.update(dentry) | ret.update(dentry) | ||||
if ret['type'] == 'file': | if ret['type'] == 'file': | ||||
content = self.content_find({'sha1_git': ret['target']}) | content = self.content_find({'sha1_git': ret['target']}) | ||||
if content: | if content: | ||||
for key in keys: | for key in keys: | ||||
ret[key] = content[key] | ret[key] = content[key] | ||||
return ret | return ret | ||||
def directory_ls(self, directory_id): | def _directory_ls(self, directory_id, recursive, prefix=b''): | ||||
if directory_id in self._directories: | |||||
for entry in self._directories[directory_id]['entries']: | |||||
ret = self._join_dentry_to_content(entry) | |||||
ret['name'] = prefix + ret['name'] | |||||
ret['dir_id'] = directory_id | |||||
yield ret | |||||
if recursive and ret['type'] == 'dir': | |||||
yield from self._directory_ls( | |||||
ret['target'], True, prefix + ret['name'] + b'/') | |||||
def directory_ls(self, directory_id, recursive=False): | |||||
"""Get entries for one directory. | """Get entries for one directory. | ||||
Args: | Args: | ||||
- directory: the directory to list entries from. | - directory: the directory to list entries from. | ||||
- recursive: if flag on, this list recursively from this directory. | - recursive: if flag on, this list recursively from this directory. | ||||
Returns: | Returns: | ||||
List of entries for such directory. | List of entries for such directory. | ||||
If `recursive=True`, names in the path of a dir/file not at the | |||||
root are concatenated with a slash (`/`). | |||||
""" | """ | ||||
if directory_id in self._directories: | yield from self._directory_ls(directory_id, recursive) | ||||
for entry in self._directories[directory_id]['entries']: | |||||
ret = self._join_dentry_to_content(entry) | |||||
ret['dir_id'] = directory_id | |||||
yield ret | |||||
def directory_entry_get_by_path(self, directory, paths): | def directory_entry_get_by_path(self, directory, paths): | ||||
"""Get the directory entry (either file or dir) from directory with path. | """Get the directory entry (either file or dir) from directory with path. | ||||
Args: | Args: | ||||
- directory: sha1 of the top level directory | - directory: sha1 of the top level directory | ||||
- paths: path to lookup from the top level directory. From left | - paths: path to lookup from the top level directory. From left | ||||
(top) to right (bottom). | (top) to right (bottom). | ||||
▲ Show 20 Lines • Show All 856 Lines • Show Last 20 Lines |