diff options
author | Tom Pollard <tom.pollard@codethink.co.uk> | 2019-03-21 12:45:38 +0000 |
---|---|---|
committer | bst-marge-bot <marge-bot@buildstream.build> | 2019-03-29 10:38:53 +0000 |
commit | 35616512815cc3edc22b7aab128744a81b21c32f (patch) | |
tree | 7f6af21e9100e71690a1b7b016aa6b62fcdbcf25 | |
parent | d20165a62536e526deb0fc32819e1d3776e75590 (diff) | |
download | buildstream-35616512815cc3edc22b7aab128744a81b21c32f.tar.gz |
_cas/cascache.py: Add opt check_exists arg to _reachable_refs_dir()
By default the reachable set() includes all file digests from a
given reachable directory/tree digest, however this does not
guarantee the file objects are actually reachable.
testutils/artifactshare.py has_artifact() ascertained if a given
artifact is available by ensuring any 'reachable' digests are
actually on the filesystem, this is made redudant with the optional
check_exists objpath check during the reachable set creation.
-rw-r--r-- | buildstream/_cas/cascache.py | 7 | ||||
-rw-r--r-- | tests/testutils/artifactshare.py | 6 |
2 files changed, 6 insertions, 7 deletions
diff --git a/buildstream/_cas/cascache.py b/buildstream/_cas/cascache.py index 19020e234..c739c7ee1 100644 --- a/buildstream/_cas/cascache.py +++ b/buildstream/_cas/cascache.py @@ -852,7 +852,7 @@ class CASCache(): a += 1 b += 1 - def _reachable_refs_dir(self, reachable, tree, update_mtime=False): + def _reachable_refs_dir(self, reachable, tree, update_mtime=False, check_exists=False): if tree.hash in reachable: return try: @@ -873,10 +873,13 @@ class CASCache(): for filenode in directory.files: if update_mtime: os.utime(self.objpath(filenode.digest)) + if check_exists: + if not os.path.exists(self.objpath(filenode.digest)): + raise FileNotFoundError reachable.add(filenode.digest.hash) for dirnode in directory.directories: - self._reachable_refs_dir(reachable, dirnode.digest, update_mtime=update_mtime) + self._reachable_refs_dir(reachable, dirnode.digest, update_mtime=update_mtime, check_exists=check_exists) def _required_blobs(self, directory_digest, *, excluded_subdirs=None): if not excluded_subdirs: diff --git a/tests/testutils/artifactshare.py b/tests/testutils/artifactshare.py index 0fca42a6c..6c484ceb7 100644 --- a/tests/testutils/artifactshare.py +++ b/tests/testutils/artifactshare.py @@ -149,13 +149,9 @@ class ArtifactShare(): tree = self.cas.resolve_ref(artifact_key) reachable = set() try: - self.cas._reachable_refs_dir(reachable, tree, update_mtime=False) + self.cas._reachable_refs_dir(reachable, tree, update_mtime=False, check_exists=True) except FileNotFoundError: return None - for digest in reachable: - object_name = os.path.join(self.cas.casdir, 'objects', digest[:2], digest[2:]) - if not os.path.exists(object_name): - return None return tree except CASError: return None |