From 31c21544652ae11bfb8a31d1f166d3cbc9c74db4 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Fri, 16 Sep 2022 18:29:05 +0200 Subject: [PATCH] common-updater-scripts: Use custom fake temporary hash MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Some update scripts (e.g. sublime4) already use all-zeroes hashes for resetting a version when updating multiple sources. When `update-source-version "${attrPath}" 0 "${lib.fakeSha256}"` was executed, u-s-v would not be able to detect that the hash changed and would fail with the following message: Failed to replace temporary source hash of '…' to the final source hash! The update script worked when we tested it because change detection itself was broken until recently: https://github.com/NixOS/nixpkgs/pull/190554 --- pkgs/common-updater/scripts/update-source-version | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version index 480fb7b2265..12a63fa9260 100755 --- a/pkgs/common-updater/scripts/update-source-version +++ b/pkgs/common-updater/scripts/update-source-version @@ -177,15 +177,15 @@ elif [[ "$oldHashAlgo" = "null" ]]; then fi case "$oldHashAlgo" in - # Lengths of hex-encoded hashes - sha256) hashLength=64 ;; - sha512) hashLength=128 ;; + # Choose a temporary hash for given algorithm. + # Not using all-zeroes hash, since that is sometimes + # used for clean-up when updating multi-source packages. + # Created by hashing “update-source-version” string. + sha256) tempHash=AzH1rZFqEH8sovZZfJykvsEmCedEZWigQFHWHl6/PdE= ;; + sha512) tempHash=KFj9Fvco4AuCgLJIGRnVzyssRf7VGP2oi5CkH6ADvj75ow3am3h8pxefOgQlO+i33Q/BBnG/ST/F7B/0BvWHxw== ;; *) die "Unhandled hash algorithm '$oldHashAlgo' in '$attr'!" ;; esac -# Make a temporary all-zeroes hash of $hashLength characters -tempHash=$(printf '%0*d' "$hashLength" 0) - if [[ -n "$sri" ]]; then # SRI hashes only support base64 # SRI hashes need to declare the hash type as part of the hash