From 17bc96df08471d36e6ab20e199679243d3ee8166 Mon Sep 17 00:00:00 2001 From: Jan Tojnar Date: Thu, 8 Sep 2022 00:37:38 +0200 Subject: [PATCH] common-updater-scripts: Fix replacement failure detections MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Previously, we only made `sed` back up the version replacement. This meant that `cmp` would already recognize the files as changed before replacing hash and the other values, and the error would not be printed. Let’s always make the `sed` create a backup so that we can detect success of each situation. This will no longer allow us to revert to the original version on failure but the updated file should be tracked in git anyway. --- .../scripts/update-source-version | 25 ++++++++----------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version index fbeb375fa891..a3a7bde17f85 100755 --- a/pkgs/common-updater/scripts/update-source-version +++ b/pkgs/common-updater/scripts/update-source-version @@ -206,30 +206,28 @@ oldHashEscaped=$(echo "$oldHash" | sed -re 's|[+]|\\&|g') tempHashEscaped=$(echo "$tempHash" | sed -re 's|[+]|\\&|g') # Replace new version -sed -i.bak "$nixFile" -re "$pattern" -if cmp -s "$nixFile" "$nixFile.bak"; then +sed -i.cmp "$nixFile" -re "$pattern" +if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace version '$oldVersion' to '$newVersion' in '$attr'!" fi # Replace new URL if [[ -n "$newUrl" ]]; then - sed -i "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|" - - if cmp -s "$nixFile" "$nixFile.bak"; then + sed -i.cmp "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|" + if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!" fi fi -sed -i "$nixFile" -re "s|\"$oldHashEscaped\"|\"$tempHash\"|" -if cmp -s "$nixFile" "$nixFile.bak"; then +sed -i.cmp "$nixFile" -re "s|\"$oldHashEscaped\"|\"$tempHash\"|" +if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace source hash of '$attr' to a temporary hash!" fi # Replace new revision, if given if [[ -n "$newRevision" ]]; then - sed -i "$nixFile" -re "s|\"$oldRevision\"|\"$newRevision\"|" - - if cmp -s "$nixFile" "$nixFile.bak"; then + sed -i.cmp "$nixFile" -re "s|\"$oldRevision\"|\"$newRevision\"|" + if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace source revision '$oldRevision' to '$newRevision' in '$attr'!" fi fi @@ -254,16 +252,15 @@ if [[ -z "$newHash" ]]; then fi if [[ -z "${ignoreSameHash}" && "$oldVersion" != "$newVersion" && "$oldHash" = "$newHash" ]]; then - mv "$nixFile.bak" "$nixFile" die "Both the old and new source hashes of '$attr.$sourceKey' were equivalent. Please fix the package's source URL to be dependent on '\${version}'!" fi -sed -i "$nixFile" -re "s|\"$tempHashEscaped\"|\"$newHash\"|" -if cmp -s "$nixFile" "$nixFile.bak"; then +sed -i.cmp "$nixFile" -re "s|\"$tempHashEscaped\"|\"$newHash\"|" +if cmp -s "$nixFile" "$nixFile.cmp"; then die "Failed to replace temporary source hash of '$attr' to the final source hash!" fi -rm -f "$nixFile.bak" +rm -f "$nixFile.cmp" rm -f "$attr.fetchlog" if [ -n "$printChanges" ]; then