From 0199e369fa118ffe31a94b67c619bd6ac3af8d0c Mon Sep 17 00:00:00 2001 From: Axel Kohlmeyer Date: Mon, 15 Jun 2020 13:46:54 -0400 Subject: [PATCH] work around race condition and minimizing download attemps for transparently downloaded potential files --- cmake/Modules/LAMMPSUtils.cmake | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/cmake/Modules/LAMMPSUtils.cmake b/cmake/Modules/LAMMPSUtils.cmake index c6b4933038..a87c0f567c 100644 --- a/cmake/Modules/LAMMPSUtils.cmake +++ b/cmake/Modules/LAMMPSUtils.cmake @@ -96,9 +96,15 @@ function(FetchPotentials pkgfolder potfolder) math(EXPR plusone "${blank}+1") string(SUBSTRING ${line} 0 ${blank} pot) string(SUBSTRING ${line} ${plusone} -1 sum) - message(STATUS "Checking external potential ${pot} from ${LAMMPS_POTENTIALS_URL}") - file(DOWNLOAD "${LAMMPS_POTENTIALS_URL}/${pot}.${sum}" "${LAMMPS_POTENTIALS_DIR}/${pot}" - EXPECTED_HASH MD5=${sum} SHOW_PROGRESS) + if(EXISTS ${LAMMPS_POTENTIALS_DIR}/${pot}) + file(MD5 "${LAMMPS_POTENTIALS_DIR}/${pot}" oldsum) + endif() + if(NOT sum STREQUAL oldsum) + message(STATUS "Checking external potential ${pot} from ${LAMMPS_POTENTIALS_URL}") + file(DOWNLOAD "${LAMMPS_POTENTIALS_URL}/${pot}.${sum}" "${CMAKE_BINARY_DIR}/${pot}" + EXPECTED_HASH MD5=${sum} SHOW_PROGRESS) + file(COPY "${CMAKE_BINARY_DIR}/${pot}" DESTINATION ${LAMMPS_POTENTIALS_DIR}) + endif() endforeach() endif() endfunction(FetchPotentials)