CMake: Fix race condition with parallel builds

If running multiple parallel processes of "xor_testfile.py" there was a
race condition between checking for the existence of the directory and
creating it. Now this is handled as a dependency in CMake.
This commit is contained in:
Alexander Sulfrian 2021-09-24 12:37:43 +02:00 committed by Micah Snyder
parent 5031593e61
commit c5c3b7558e
2 changed files with 4 additions and 3 deletions

View file

@ -62,6 +62,9 @@ if(ENABLE_UNRAR)
)
endif()
add_custom_target(tgt_clamav_hdb_scanfiles ALL
COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/clamav_hdb_scanfiles)
# Decrypt test file
function(decrypt_testfile test_file)
add_custom_command(OUTPUT clamav_hdb_scanfiles/${test_file}
@ -71,6 +74,7 @@ function(decrypt_testfile test_file)
--out_file ${CMAKE_CURRENT_BINARY_DIR}/clamav_hdb_scanfiles/${test_file}
COMMENT "Decrypting test file ${test_file}...")
add_custom_target(tgt_${test_file} ALL DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/clamav_hdb_scanfiles/${test_file})
ADD_DEPENDENCIES(tgt_${test_file} tgt_clamav_hdb_scanfiles)
endfunction()
foreach(TESTFILE ${TESTFILES})

View file

@ -53,9 +53,6 @@ def main():
# Write out the result to the destination file.
try:
if not out_file.parent.exists():
out_file.parent.mkdir()
with out_file.open('w+b') as out_file_fd:
out_file_fd.write(out_file_bytes)