From d2dd79f3c5bd5684a10d40670e2351e4252020b3 Mon Sep 17 00:00:00 2001 From: Janic Duplessis Date: Mon, 6 Mar 2023 02:59:35 -0800 Subject: [PATCH] Don't download hermes nightly tarball if it exists (#36368) Summary: Currently the hermes tarball will be re-downloaded every time we run pod update even if the file already exists. This adds a check to avoid downloading it if it already exists. To avoid partial downloads causing issues (if the script is interrupted) we download first to a different file and rename it when done. ## Changelog [IOS] [FIXED] - Don't download hermes nightly tarball if it exists Pull Request resolved: https://github.com/facebook/react-native/pull/36368 Test Plan: Tested in an app using nightly builds that the download is only done once when running multiple pod update. Reviewed By: sshic Differential Revision: D43815772 Pulled By: cipolleschi fbshipit-source-id: 9dedb79cab1f1cb37cd82b425d93515c6e1728c1 --- sdks/hermes-engine/hermes-utils.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/sdks/hermes-engine/hermes-utils.rb b/sdks/hermes-engine/hermes-utils.rb index 4098b2071d0ca2..06f36447d50adc 100644 --- a/sdks/hermes-engine/hermes-utils.rb +++ b/sdks/hermes-engine/hermes-utils.rb @@ -110,9 +110,13 @@ def download_nightly_hermes(react_native_path, version) tarball_url = nightly_tarball_url(version) destination_folder = "#{react_native_path}/sdks/downloads" - destination_path = "#{destination_folder}/hermes-ios.tar.gz" + destination_path = "#{destination_folder}/hermes-ios-#{version}.tar.gz" - `mkdir -p "#{destination_folder}" && curl "#{tarball_url}" -Lo "#{destination_path}"` + unless File.exist?(destination_path) + # Download to a temporary file first so we don't cache incomplete downloads. + tmp_file = "#{destination_folder}/hermes-ios.download" + `mkdir -p "#{destination_folder}" && curl "#{tarball_url}" -Lo "#{tmp_file}" && mv "#{tmp_file}" "#{destination_path}"` + end return destination_path end