summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-02-25 11:01:49 +0100
committerJürg Billeter <j@bitron.ch>2019-02-26 12:12:46 +0100
commit68f5dbac61c8ccb0c48d560e2208eac6305ab321 (patch)
treee79fd2a265abd02b1c01d2d6e7964fbb037ca433
parentf7bc89ea3b31f9f46f4e3ac67071d0dbd37094ac (diff)
downloadbuildstream-68f5dbac61c8ccb0c48d560e2208eac6305ab321.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.py66
1 files changed, 37 insertions, 29 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py
index fe25efce6..3eef94803 100644
--- a/buildstream/_cas/cascache.py
+++ b/buildstream/_cas/cascache.py
@@ -170,7 +170,7 @@ class CASCache():
with utils._tempdir(prefix='tmp', dir=self.tmpdir) as tmpdir:
checkoutdir = os.path.join(tmpdir, ref)
- self._checkout(checkoutdir, tree)
+ self.checkout(checkoutdir, tree)
try:
utils.move_atomic(checkoutdir, dest)
@@ -182,6 +182,42 @@ class CASCache():
return originaldest
+ # 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:
+ # Don't try to checkout a dangling ref
+ if os.path.exists(self.objpath(dirnode.digest)):
+ 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.
@@ -631,34 +667,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:
- # Don't try to checkout a dangling ref
- if os.path.exists(self.objpath(dirnode.digest)):
- 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)