diff options
author | Jürg Billeter <j@bitron.ch> | 2019-02-25 11:05:33 +0100 |
---|---|---|
committer | Abderrahim Kitouni <akitouni@gnome.org> | 2020-08-26 12:47:05 +0100 |
commit | fd130e480b08b7b69f23c70119efd1f7e7ad375d (patch) | |
tree | b7bb3947ea3d6550b90582f447b3056fdf249889 | |
parent | 104d42b1934ecf74d6156c0fc7b41d964cbb60b0 (diff) | |
download | buildstream-fd130e480b08b7b69f23c70119efd1f7e7ad375d.tar.gz |
_casbaseddirectory.py: Use CASCache.checkout() in export_files()
This eliminates code duplication.
-rw-r--r-- | buildstream/storage/_casbaseddirectory.py | 37 |
1 files changed, 2 insertions, 35 deletions
diff --git a/buildstream/storage/_casbaseddirectory.py b/buildstream/storage/_casbaseddirectory.py index a01d37daa..e77921252 100644 --- a/buildstream/storage/_casbaseddirectory.py +++ b/buildstream/storage/_casbaseddirectory.py @@ -28,13 +28,11 @@ See also: :ref:`sandboxing`. """ import os -import stat from .._protos.build.bazel.remote.execution.v2 import remote_execution_pb2 -from .._exceptions import BstError from .directory import Directory, VirtualDirectoryError, _FileType from ._filebaseddirectory import FileBasedDirectory -from ..utils import FileListResult, safe_copy, list_relative_paths +from ..utils import FileListResult, list_relative_paths class IndexEntry(): @@ -689,38 +687,7 @@ class CasBasedDirectory(Directory): """ - if not os.path.exists(to_directory): - os.mkdir(to_directory) - - for entry in self.pb2_directory.directories: - if entry.name not in self.index: - raise VirtualDirectoryError("CasDir {} contained {} in directories but not in the index" - .format(str(self), entry.name)) - if not self._directory_read: - raise VirtualDirectoryError("CasDir {} has not been indexed yet".format(str(self))) - dest_dir = os.path.join(to_directory, entry.name) - if not os.path.exists(dest_dir): - os.mkdir(dest_dir) - target = self.descend([entry.name]) - target.export_files(dest_dir) - for entry in self.pb2_directory.files: - # Extract the entry to a single file - dest_name = os.path.join(to_directory, entry.name) - src_name = self.cas_cache.objpath(entry.digest) - safe_copy(src_name, dest_name) - if entry.is_executable: - os.chmod(dest_name, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) - for entry in self.pb2_directory.symlinks: - src_name = os.path.join(to_directory, entry.name) - target_name = entry.target - try: - os.symlink(target_name, src_name) - except FileExistsError as e: - raise BstError(("Cannot create a symlink named {} pointing to {}." + - " The original error was: {}"). - format(src_name, entry.target, e)) + self.cas_cache.checkout(to_directory, self._get_digest(), can_link=can_link) def export_to_tar(self, tarfile, destination_dir, mtime=0): raise NotImplementedError() |