From e31eb9a58d62043cdc9ba7db8b6b2dd19f6e1c5d Mon Sep 17 00:00:00 2001 From: gilice <104317939+gilice@users.noreply.github.com> Date: Tue, 21 Mar 2023 17:30:07 +0100 Subject: [PATCH] dart: Make update script atomic --- pkgs/development/compilers/dart/sources.nix | 3 --- pkgs/development/compilers/dart/update.sh | 19 ++++++++----------- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/pkgs/development/compilers/dart/sources.nix b/pkgs/development/compilers/dart/sources.nix index 13aaac2bb327..40e25d358477 100644 --- a/pkgs/development/compilers/dart/sources.nix +++ b/pkgs/development/compilers/dart/sources.nix @@ -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"; }; } -### diff --git a/pkgs/development/compilers/dart/update.sh b/pkgs/development/compilers/dart/update.sh index c148f09b52a2..87f430cd5d2d 100755 --- a/pkgs/development/compilers/dart/update.sh +++ b/pkgs/development/compilers/dart/update.sh @@ -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"