summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTiago Gomes <tiago.gomes@codethink.co.uk>2018-09-13 15:14:27 +0100
committerJürg Billeter <j@bitron.ch>2018-09-30 08:33:46 +0200
commitb842658cf4b0d3e8d57552fdd5811a969e878392 (patch)
treeab08b09d8c00d235384b82240cfa1e336b25cb69
parent34e81ae1835cb8732798e7d4eab4d470e96fad13 (diff)
downloadbuildstream-b842658cf4b0d3e8d57552fdd5811a969e878392.tar.gz
artifactcache: improve _create_tree()
* Rename it to _commit_directory() because… it is what it does; and also for symmetry with _fetch_directory(). * Rename digest to dir_digest to make it clear this is a digest for a directory. A following commit will also reuse the same variable name * Document method.
-rw-r--r--buildstream/_artifactcache/cascache.py23
1 files changed, 19 insertions, 4 deletions
diff --git a/buildstream/_artifactcache/cascache.py b/buildstream/_artifactcache/cascache.py
index a7b92d6e2..d48c8aa01 100644
--- a/buildstream/_artifactcache/cascache.py
+++ b/buildstream/_artifactcache/cascache.py
@@ -115,7 +115,7 @@ class CASCache(ArtifactCache):
def commit(self, element, content, keys):
refs = [self.get_artifact_fullname(element, key) for key in keys]
- tree = self._create_tree(content)
+ tree = self._commit_directory(content)
for ref in refs:
self.set_ref(ref, tree)
@@ -623,7 +623,21 @@ class CASCache(ArtifactCache):
def _refpath(self, ref):
return os.path.join(self.casdir, 'refs', 'heads', ref)
- def _create_tree(self, path, *, digest=None):
+ # _commit_directory():
+ #
+ # Adds local directory to content addressable store.
+ #
+ # Adds files, symbolic links and recursively other directories in
+ # a local directory to the content addressable store.
+ #
+ # Args:
+ # path (str): Path to the directory to add.
+ # dir_digest (Digest): An optional Digest object to use.
+ #
+ # Returns:
+ # (Digest): Digest object for the directory added.
+ #
+ def _commit_directory(self, path, *, dir_digest=None):
directory = remote_execution_pb2.Directory()
for name in sorted(os.listdir(path)):
@@ -632,7 +646,7 @@ class CASCache(ArtifactCache):
if stat.S_ISDIR(mode):
dirnode = directory.directories.add()
dirnode.name = name
- self._create_tree(full_path, digest=dirnode.digest)
+ self._commit_directory(full_path, dir_digest=dirnode.digest)
elif stat.S_ISREG(mode):
filenode = directory.files.add()
filenode.name = name
@@ -645,7 +659,8 @@ class CASCache(ArtifactCache):
else:
raise ArtifactError("Unsupported file type for {}".format(full_path))
- return self.add_object(digest=digest, buffer=directory.SerializeToString())
+ return self.add_object(digest=dir_digest,
+ buffer=directory.SerializeToString())
def _get_subdir(self, tree, subdir):
head, name = os.path.split(subdir)