From 58674237780f71bfccd9f494203f2ae7e5ef3d50 Mon Sep 17 00:00:00 2001 From: Taylor Salo Date: Tue, 27 Feb 2024 10:37:44 -0500 Subject: [PATCH] Fix potential atlas file race condition (#1066) --- xcp_d/utils/atlas.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/xcp_d/utils/atlas.py b/xcp_d/utils/atlas.py index cb035f4a6..3e39d5a9b 100644 --- a/xcp_d/utils/atlas.py +++ b/xcp_d/utils/atlas.py @@ -190,5 +190,8 @@ def copy_atlas(name_source, in_file, output_dir, atlas): atlas_out_dir = os.path.join(output_dir, f"xcp_d/atlases/atlas-{atlas}") os.makedirs(atlas_out_dir, exist_ok=True) out_atlas_file = os.path.join(atlas_out_dir, atlas_basename) - shutil.copyfile(in_file, out_atlas_file) + # Don't copy the file if it exists, to prevent any race conditions between parallel processes. + if not os.path.isfile(out_atlas_file): + shutil.copyfile(in_file, out_atlas_file) + return out_atlas_file