mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-11-22 15:40:19 +00:00
Meta: Download files at configure time a bit more atomically
Download files to a temporary location, then only move the downloaded file to the real location once the download is complete. This prevents CMake from being confused about partially-downloaded files, e.g. if someone presses ctrl+c in the middle of a download. Note the GN build already behaves this way.
This commit is contained in:
parent
ec63f442f9
commit
2f4e2436e8
Notes:
sideshowbarker
2024-07-17 22:41:14 +09:00
Author: https://github.com/trflynn89 Commit: https://github.com/SerenityOS/serenity/commit/2f4e2436e8 Pull-request: https://github.com/SerenityOS/serenity/pull/24407 Issue: https://github.com/SerenityOS/serenity/issues/24401 Reviewed-by: https://github.com/nico ✅
1 changed files with 5 additions and 2 deletions
|
@ -210,20 +210,23 @@ function(download_file_multisource urls path)
|
|||
if (NOT ENABLE_NETWORK_DOWNLOADS)
|
||||
message(FATAL_ERROR "${path} does not exist, and unable to download it")
|
||||
endif()
|
||||
|
||||
get_filename_component(file "${path}" NAME)
|
||||
set(tmp_path "${path}.tmp")
|
||||
|
||||
foreach(url ${urls})
|
||||
message(STATUS "Downloading file ${file} from ${url}")
|
||||
|
||||
file(DOWNLOAD "${url}" "${path}" INACTIVITY_TIMEOUT 10 STATUS download_result ${DOWNLOAD_SHA256})
|
||||
file(DOWNLOAD "${url}" "${tmp_path}" INACTIVITY_TIMEOUT 10 STATUS download_result ${DOWNLOAD_SHA256})
|
||||
list(GET download_result 0 status_code)
|
||||
list(GET download_result 1 error_message)
|
||||
|
||||
if (status_code EQUAL 0)
|
||||
file(RENAME "${tmp_path}" "${path}")
|
||||
break()
|
||||
endif()
|
||||
|
||||
file(REMOVE "${path}")
|
||||
file(REMOVE "${tmp_path}")
|
||||
message(WARNING "Failed to download ${url}: ${error_message}")
|
||||
endforeach()
|
||||
|
||||
|
|
Loading…
Reference in a new issue