This is an automated email from the ASF dual-hosted git repository. tvb pushed a commit to branch tristan/virtual-directory-cleanup in repository https://gitbox.apache.org/repos/asf/buildstream.git
commit 6abcc0905139d2bc1335c4709a46505788433f1c Author: Tristan van Berkom <[email protected]> AuthorDate: Fri Mar 4 19:05:53 2022 +0900 storage: Raise only DirectoryError from Directory backends The API advertizes that it will raise DirectoryError for system errors, better to raise DirectoryError than FileNotFoundError or other native python system errors. With the exception that we still raise ValueError for clear cut programming errors which should not be handled by the caller but rather their code should be fixed. --- src/buildstream/storage/_casbaseddirectory.py | 8 ++++---- src/buildstream/storage/_filebaseddirectory.py | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/buildstream/storage/_casbaseddirectory.py b/src/buildstream/storage/_casbaseddirectory.py index d99ea5d..abe88af 100644 --- a/src/buildstream/storage/_casbaseddirectory.py +++ b/src/buildstream/storage/_casbaseddirectory.py @@ -313,7 +313,7 @@ class CasBasedDirectory(Directory): self.__validate_path_component(name) entry = self.index.get(name) if not entry: - raise FileNotFoundError("{} not found in {}".format(name, str(self))) + raise DirectoryError("{} not found in {}".format(name, str(self))) if entry.type == _FileType.DIRECTORY and not recursive: subdir = entry.get_directory(self) @@ -733,14 +733,14 @@ class CasBasedDirectory(Directory): if "r" in mode: if not entry: - raise FileNotFoundError("{} not found in {}".format(path[-1], str(subdir))) + raise DirectoryError("{} not found in {}".format(path[-1], str(subdir))) # Read-only access, allow direct access to CAS object with open(self.cas_cache.objpath(entry.digest), mode, encoding=encoding) as f: yield f else: if "x" in mode and entry: - raise FileExistsError("{} already exists in {}".format(path[-1], str(subdir))) + raise DirectoryError("{} already exists in {}".format(path[-1], str(subdir))) with utils._tempnamedfile(mode, encoding=encoding, dir=self.cas_cache.tmpdir) as f: # Make sure the temporary file is readable by buildbox-casd @@ -819,7 +819,7 @@ class CasBasedDirectory(Directory): self.__validate_path_component(path[-1]) target = subdir.index.get(path[-1]) if target is None: - raise FileNotFoundError("{} not found in {}".format(path[-1], str(subdir))) + raise DirectoryError("{} not found in {}".format(path[-1], str(subdir))) if follow_symlinks and target.type == _FileType.SYMLINK: linklocation = target.target diff --git a/src/buildstream/storage/_filebaseddirectory.py b/src/buildstream/storage/_filebaseddirectory.py index ecf8f04..540a965 100644 --- a/src/buildstream/storage/_filebaseddirectory.py +++ b/src/buildstream/storage/_filebaseddirectory.py @@ -271,7 +271,7 @@ class FileBasedDirectory(Directory): # This check is not atomic, however, we're operating with a # single thread in a private directory tree. if subdir.exists(path[-1]): - raise FileExistsError("{} already exists in {}".format(path[-1], str(subdir))) + raise DirectoryError("{} already exists in {}".format(path[-1], str(subdir))) mode = "w" + mode[1:] return utils.save_file_atomic(newpath, mode=mode, encoding=encoding)
