diff options
author | Jürg Billeter <j@bitron.ch> | 2019-02-25 11:01:49 +0100 |
---|---|---|
committer | Abderrahim Kitouni <akitouni@gnome.org> | 2020-08-26 12:47:05 +0100 |
commit | 9e959e7b97b72bf54fc5dee11810c510dbf1f6cc (patch) | |
tree | d8a6b0668b5db414df3be4bbe4e871a64ec721ba | |
parent | a22c2df5040c5abbdc7a43e2044e549f93550925 (diff) | |
download | buildstream-9e959e7b97b72bf54fc5dee11810c510dbf1f6cc.tar.gz |
cascache.py: Make _checkout() public
This allows CasBasedDirectory.export_files() to use CASCache.checkout(),
eliminating code duplication.
-rw-r--r-- | buildstream/_cas/cascache.py | 62 |
1 files changed, 35 insertions, 27 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py index 27020a099..5f229d9d8 100644 --- a/buildstream/_cas/cascache.py +++ b/buildstream/_cas/cascache.py @@ -157,7 +157,7 @@ class CASCache(): with tempfile.TemporaryDirectory(prefix='tmp', dir=self.tmpdir) as tmpdir: checkoutdir = os.path.join(tmpdir, ref) - self._checkout(checkoutdir, tree) + self.checkout(checkoutdir, tree) os.makedirs(os.path.dirname(dest), exist_ok=True) try: @@ -173,6 +173,40 @@ class CASCache(): return dest + # checkout(): + # + # Checkout the specified directory digest. + # + # Args: + # dest (str): The destination path + # tree (Digest): The directory digest to extract + # + def checkout(self, dest, tree): + os.makedirs(dest, exist_ok=True) + + directory = remote_execution_pb2.Directory() + + with open(self.objpath(tree), 'rb') as f: + directory.ParseFromString(f.read()) + + for filenode in directory.files: + # regular file, create hardlink + fullpath = os.path.join(dest, filenode.name) + os.link(self.objpath(filenode.digest), fullpath) + + if filenode.is_executable: + os.chmod(fullpath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | + stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) + + for dirnode in directory.directories: + fullpath = os.path.join(dest, dirnode.name) + self.checkout(fullpath, dirnode.digest) + + for symlinknode in directory.symlinks: + # symlink + fullpath = os.path.join(dest, symlinknode.name) + os.symlink(symlinknode.target, fullpath) + # commit(): # # Commit directory to cache. @@ -641,32 +675,6 @@ class CASCache(): # Local Private Methods # ################################################ - def _checkout(self, dest, tree): - os.makedirs(dest, exist_ok=True) - - directory = remote_execution_pb2.Directory() - - with open(self.objpath(tree), 'rb') as f: - directory.ParseFromString(f.read()) - - for filenode in directory.files: - # regular file, create hardlink - fullpath = os.path.join(dest, filenode.name) - os.link(self.objpath(filenode.digest), fullpath) - - if filenode.is_executable: - os.chmod(fullpath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH) - - for dirnode in directory.directories: - fullpath = os.path.join(dest, dirnode.name) - self._checkout(fullpath, dirnode.digest) - - for symlinknode in directory.symlinks: - # symlink - fullpath = os.path.join(dest, symlinknode.name) - os.symlink(symlinknode.target, fullpath) - def _refpath(self, ref): return os.path.join(self.casdir, 'refs', 'heads', ref) |