diff options
| -rw-r--r-- | buildscripts/scons_cache_prune.py | 6 | ||||
| -rw-r--r-- | site_scons/site_tools/validate_cache_dir.py | 13 |
2 files changed, 15 insertions, 4 deletions
diff --git a/buildscripts/scons_cache_prune.py b/buildscripts/scons_cache_prune.py index 9b32db16b1f..4306cc56a96 100644 --- a/buildscripts/scons_cache_prune.py +++ b/buildscripts/scons_cache_prune.py @@ -100,6 +100,12 @@ def prune_cache(cache_path, cache_size_gb, clean_ratio): return False cache_item = contents.pop() + + # check the atime again just to make sure something wasn't accessed while + # we pruning other files. + if cache_item.time < os.stat(cache_item.path).st_atime: + continue + to_remove = cache_item.path + ".del" try: os.rename(cache_item.path, to_remove) diff --git a/site_scons/site_tools/validate_cache_dir.py b/site_scons/site_tools/validate_cache_dir.py index ff7e7fe98f9..b1df5326eab 100644 --- a/site_scons/site_tools/validate_cache_dir.py +++ b/site_scons/site_tools/validate_cache_dir.py @@ -25,6 +25,7 @@ import json import os import pathlib import shutil +import tempfile import traceback @@ -106,10 +107,14 @@ class CacheDirValidate(SCons.CacheDir.CacheDir): if not csig: raise InvalidChecksum(cls.get_hash_path(src_file), dst, f"no content_hash data found") - try: - shutil.copy2(src_file, dst) - except OSError as ex: - raise CacheTransferFailed(src_file, dst, f"failed to copy from cache: {ex}") from ex + with tempfile.TemporaryDirectory() as tmpdirname: + dst_tmp = pathlib.Path(tmpdirname) / os.path.basename(dst) + try: + shutil.copy2(src_file, dst_tmp) + except OSError as ex: + raise CacheTransferFailed(src_file, dst, f"failed to copy from cache: {ex}") from ex + else: + shutil.move(dst_tmp, dst) new_csig = SCons.Util.MD5filesignature(dst, chunksize=SCons.Node.FS.File.md5_chunksize*1024) |
