about summary refs log tree commit diff
path: root/pkgs/common-updater
diff options
context:
space:
mode:
authorJan Tojnar <jtojnar@gmail.com>2022-09-08 00:37:38 +0200
committerJan Tojnar <jtojnar@gmail.com>2022-09-09 22:31:28 +0200
commit17bc96df08471d36e6ab20e199679243d3ee8166 (patch)
tree5385a6108cbedabbd848eb8c3f19cbfe45e9bd6a /pkgs/common-updater
parentf31881a6198af697e80ce7bf322fddd469176d43 (diff)
common-updater-scripts: Fix replacement failure detections
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.
Diffstat (limited to 'pkgs/common-updater')
-rwxr-xr-xpkgs/common-updater/scripts/update-source-version25
1 files changed, 11 insertions, 14 deletions
diff --git a/pkgs/common-updater/scripts/update-source-version b/pkgs/common-updater/scripts/update-source-version
index fbeb375fa8918..a3a7bde17f853 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