summaryrefslogtreecommitdiff
path: root/site_scons/site_tools/validate_cache_dir.py
diff options
context:
space:
mode:
authorDaniel Moody <daniel.moody@mongodb.com>2022-01-14 16:31:22 -0600
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-01-19 20:12:38 +0000
commitd20d317c08fd48b71f790c1bb013aa61c6f0f4b7 (patch)
tree20bac06d4f3e15f05a8d7cef129f9907598641e3 /site_scons/site_tools/validate_cache_dir.py
parent946fdd81c75328162a5198c11bd402eb5c4f3943 (diff)
downloadmongo-d20d317c08fd48b71f790c1bb013aa61c6f0f4b7.tar.gz
SERVER-62680 write cache retrievals into a tmp location before final destination.
Diffstat (limited to 'site_scons/site_tools/validate_cache_dir.py')
-rw-r--r--site_scons/site_tools/validate_cache_dir.py13
1 files changed, 9 insertions, 4 deletions
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)