Commit 35616512 authored by Tom Pollard's avatar Tom Pollard Committed by bst-marge-bot

_cas/ 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/ 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.
parent d20165a6
......@@ -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:
......@@ -873,10 +873,13 @@ class CASCache():
for filenode in directory.files:
if update_mtime:
if check_exists:
if not os.path.exists(self.objpath(filenode.digest)):
raise FileNotFoundError
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:
......@@ -149,13 +149,9 @@ class ArtifactShare():
tree = self.cas.resolve_ref(artifact_key)
reachable = set()
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment