summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-02-25 11:04:18 +0100
committerAbderrahim Kitouni <akitouni@gnome.org>2020-08-26 12:47:05 +0100
commit104d42b1934ecf74d6156c0fc7b41d964cbb60b0 (patch)
treeab762eff777e01e6ddc3f330e4ce155d18a5f9f8
parent9e959e7b97b72bf54fc5dee11810c510dbf1f6cc (diff)
downloadbuildstream-104d42b1934ecf74d6156c0fc7b41d964cbb60b0.tar.gz
cascache.py: Add can_link parameter to checkout()
This allows CasBasedDirectory.export_files() to use CASCache.checkout(), eliminating code duplication.
-rw-r--r--buildstream/_cas/cascache.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py
index 5f229d9d8..c660176f1 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, can_link=True)
os.makedirs(os.path.dirname(dest), exist_ok=True)
try:
@@ -180,8 +180,9 @@ class CASCache():
# Args:
# dest (str): The destination path
# tree (Digest): The directory digest to extract
+ # can_link (bool): Whether we can create hard links in the destination
#
- def checkout(self, dest, tree):
+ def checkout(self, dest, tree, *, can_link=False):
os.makedirs(dest, exist_ok=True)
directory = remote_execution_pb2.Directory()
@@ -192,7 +193,10 @@ class CASCache():
for filenode in directory.files:
# regular file, create hardlink
fullpath = os.path.join(dest, filenode.name)
- os.link(self.objpath(filenode.digest), fullpath)
+ if can_link:
+ utils.safe_link(self.objpath(filenode.digest), fullpath)
+ else:
+ utils.safe_copy(self.objpath(filenode.digest), fullpath)
if filenode.is_executable:
os.chmod(fullpath, stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR |
@@ -200,7 +204,7 @@ class CASCache():
for dirnode in directory.directories:
fullpath = os.path.join(dest, dirnode.name)
- self.checkout(fullpath, dirnode.digest)
+ self.checkout(fullpath, dirnode.digest, can_link=can_link)
for symlinknode in directory.symlinks:
# symlink