diff options
author | Angelos Evripiotis <jevripiotis@bloomberg.net> | 2019-06-11 14:32:04 +0100 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-06-18 09:45:00 +0000 |
commit | fe9a1dc1995f0da93c65ad9eb77d0e18061b3735 (patch) | |
tree | a0af86882044eb6803e76c0f9d8a86686f16167a /src/buildstream/storage | |
parent | 64b4ddae33c373ac19850d36970a827ba360744c (diff) | |
download | buildstream-fe9a1dc1995f0da93c65ad9eb77d0e18061b3735.tar.gz |
_casbaseddirectory: match methods to base class
Update import_single_file and list_relative_paths to match the Directory
base class. This ensures that CasBasedDirectory is a fully substitutable
Directory.
By making the signatures deliberately match, we can use PyLint to ensure
the signatures don't accidentally differ.
Diffstat (limited to 'src/buildstream/storage')
-rw-r--r-- | src/buildstream/storage/_casbaseddirectory.py | 41 |
1 files changed, 28 insertions, 13 deletions
diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py index 94e6e09c7..29aee7ad3 100644 --- a/src/buildstream/storage/_casbaseddirectory.py +++ b/src/buildstream/storage/_casbaseddirectory.py @@ -394,16 +394,16 @@ class CasBasedDirectory(Directory): return result - def import_single_file(self, srcpath): + def import_single_file(self, external_pathspec): result = FileListResult() - if self._check_replacement(os.path.basename(srcpath), - os.path.dirname(srcpath), + if self._check_replacement(os.path.basename(external_pathspec), + os.path.dirname(external_pathspec), result): - self._add_file(os.path.dirname(srcpath), - os.path.basename(srcpath), - modified=os.path.basename(srcpath) + self._add_file(os.path.dirname(external_pathspec), + os.path.basename(external_pathspec), + modified=os.path.basename(external_pathspec) in result.overwritten) - result.files_written.append(srcpath) + result.files_written.append(external_pathspec) return result def set_deterministic_mtime(self): @@ -507,10 +507,25 @@ class CasBasedDirectory(Directory): if i and i.modified: yield p - def list_relative_paths(self, relpath=""): + def list_relative_paths(self): """Provide a list of all relative paths. - Return value: List(str) - list of all paths + Yields: + (List(str)) - list of all files with relative paths. + + """ + yield from self._list_prefixed_relative_paths() + + def _list_prefixed_relative_paths(self, prefix=""): + """Provide a list of all relative paths. + + Arguments: + prefix (str): an optional prefix to the relative paths, this is + also emitted by itself. + + Yields: + (List(str)) - list of all files with relative paths. + """ file_list = list(filter(lambda i: i[1].type != _FileType.DIRECTORY, @@ -518,15 +533,15 @@ class CasBasedDirectory(Directory): directory_list = filter(lambda i: i[1].type == _FileType.DIRECTORY, self.index.items()) - if relpath != "": - yield relpath + if prefix != "": + yield prefix for (k, v) in sorted(file_list): - yield os.path.join(relpath, k) + yield os.path.join(prefix, k) for (k, v) in sorted(directory_list): subdir = v.get_directory(self) - yield from subdir.list_relative_paths(relpath=os.path.join(relpath, k)) + yield from subdir._list_prefixed_relative_paths(prefix=os.path.join(prefix, k)) def get_size(self): digest = self._get_digest() |