common-updater-scripts: keep the unescaped oldVersion

Previously, we escaped the old version in place for use in sed commands,
and then had to use that in error messages. We can do better.
gstqt5
Jan Tojnar 2019-04-12 18:54:13 +02:00
parent e98c804cc9
commit 1b507bea4d
No known key found for this signature in database
GPG Key ID: 7FAB2A15F7A607A4
1 changed files with 7 additions and 7 deletions

View File

@ -109,13 +109,13 @@ if [ "$oldVersion" = "$newVersion" ]; then
fi
# Escape regex metacharacter that are allowed in store path names
oldVersion=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
oldUrl=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
oldVersionEscaped=$(echo "$oldVersion" | sed -re 's|[.+]|\\&|g')
oldUrlEscaped=$(echo "$oldUrl" | sed -re 's|[${}.+]|\\&|g')
if [ $(grep -c -E "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersion\"" "$nixFile") = 1 ]; then
pattern="/\b$versionKey\b\s*=/ s|\"$oldVersion\"|\"$newVersion\"|"
elif [ $(grep -c -E "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersion\"" "$nixFile") = 1 ]; then
pattern="/\bname\b\s*=/ s|-$oldVersion\"|-$newVersion\"|"
if [ $(grep -c -E "^\s*(let\b)?\s*$versionKey\s*=\s*\"$oldVersionEscaped\"" "$nixFile") = 1 ]; then
pattern="/\b$versionKey\b\s*=/ s|\"$oldVersionEscaped\"|\"$newVersion\"|"
elif [ $(grep -c -E "^\s*(let\b)?\s*name\s*=\s*\"[^\"]+-$oldVersionEscaped\"" "$nixFile") = 1 ]; then
pattern="/\bname\b\s*=/ s|-$oldVersionEscaped\"|-$newVersion\"|"
else
die "Couldn't figure out where out where to patch in new version in '$attr'!"
fi
@ -128,7 +128,7 @@ fi
# Replace new URL
if [ -n "$newUrl" ]; then
sed -i "$nixFile" -re "s|\"$oldUrl\"|\"$newUrl\"|"
sed -i "$nixFile" -re "s|\"$oldUrlEscaped\"|\"$newUrl\"|"
if cmp -s "$nixFile" "$nixFile.bak"; then
die "Failed to replace source URL '$oldUrl' to '$newUrl' in '$attr'!"