dart: Make update script atomic

This commit is contained in:
gilice 2023-03-21 17:30:07 +01:00
parent 8b7b6bac2c
commit e31eb9a58d
2 changed files with 8 additions and 14 deletions

View File

@ -1,5 +1,3 @@
# This file was generated by ./update.sh.
# If you do not find a line of three #-s at the end, it is broken and should not be used.
let version = "2.19.3"; in
{ fetchurl }: {
versionUsed = version;
@ -24,4 +22,3 @@ let version = "2.19.3"; in
sha256 = "0xksis14ff6bzjvycgxgldg96n88rh42adjyrrhcay2s183vh480";
};
}
###

View File

@ -3,7 +3,7 @@
set -euo pipefail
# so if the script fails, debug logs are on stdenv
# so if the script fails, debug logs are on stderr
log() {
>&2 echo "DART_UPDATER: $@"
}
@ -13,12 +13,11 @@ NEW_VER_DETAILS=$(curl -sL https://storage.googleapis.com/dart-archive/channels/
NEW_VER=$(jq -r '.version' <<< "$NEW_VER_DETAILS")
MY_PATH=$(dirname $(realpath "$0"))
SRC_FILE="$MY_PATH/sources.nix"
SRC_FILE=$(mktemp)
log "file to write is $SRC_FILE"
PRELUDE="# This file was generated by ./update.sh.
# If you do not find a line of three #-s at the end, it is broken and should not be used.
let version = \"$NEW_VER\"; in
PRELUDE="let version = \"$NEW_VER\"; in
{ fetchurl }: {
versionUsed = version;"
echo "$PRELUDE" > "$SRC_FILE"
@ -54,8 +53,7 @@ write_for_platform() {
echo "$FETCHER" >> $SRC_FILE
done
log "finished for $1
---"
log "finished for $1"
}
@ -73,8 +71,7 @@ declare -A LIN_PLATFORMS=( ["x86_64-linux"]="$X8664"
write_for_platform "DARWIN_PLATFORMS" "macos"
write_for_platform "LIN_PLATFORMS" "linux"
echo '}
###' >> $SRC_FILE
echo '}' >> $SRC_FILE
log "Replacing version in dart/default.nix"
sed -i "s/$UPDATE_NIX_OLD_VERSION/$NEW_VER/g" "$MY_PATH/default.nix"
log "moving tempfile to target directory"
mv "$SRC_FILE" "$MY_PATH/sources.nix"