summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJürg Billeter <j@bitron.ch>2019-07-23 10:30:14 +0200
committerJürg Billeter <j@bitron.ch>2019-08-08 06:55:23 +0200
commit5c4b448deeffbdf7d088aa292613624c0c296c3e (patch)
tree744192dc5a5c8699f8720c75c7b8f2f1545b6698
parentb007a3d8e354e16d0f9daa70a2b3418b4f9b735b (diff)
downloadbuildstream-5c4b448deeffbdf7d088aa292613624c0c296c3e.tar.gz
cascache.py: Add update_mtime parameter to contains_directory()
-rw-r--r--src/buildstream/_cas/cascache.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/src/buildstream/_cas/cascache.py b/src/buildstream/_cas/cascache.py
index 479b08a02..535d9199e 100644
--- a/src/buildstream/_cas/cascache.py
+++ b/src/buildstream/_cas/cascache.py
@@ -124,24 +124,33 @@ class CASCache():
# Args:
# digest (Digest): The directory digest to check
# with_files (bool): Whether to check files as well
+ # update_mtime (bool): Whether to update the timestamp
#
# Returns: True if the directory is available in the local cache
#
- def contains_directory(self, digest, *, with_files):
+ def contains_directory(self, digest, *, with_files, update_mtime=False):
try:
directory = remote_execution_pb2.Directory()
- with open(self.objpath(digest), 'rb') as f:
+ path = self.objpath(digest)
+ with open(path, 'rb') as f:
directory.ParseFromString(f.read())
+ if update_mtime:
+ os.utime(f.fileno())
# Optionally check presence of files
if with_files:
for filenode in directory.files:
- if not os.path.exists(self.objpath(filenode.digest)):
+ path = self.objpath(filenode.digest)
+ if update_mtime:
+ # No need for separate `exists()` call as this will raise
+ # FileNotFoundError if the file does not exist.
+ os.utime(path)
+ elif not os.path.exists(path):
return False
# Check subdirectories
for dirnode in directory.directories:
- if not self.contains_directory(dirnode.digest, with_files=with_files):
+ if not self.contains_directory(dirnode.digest, with_files=with_files, update_mtime=update_mtime):
return False
return True