From 2193b42822f2a832f8e3f3e190f565b2e2eb2b3e Mon Sep 17 00:00:00 2001 From: Julian Ospald Date: Mon, 8 Oct 2018 22:42:04 +0800 Subject: [PATCH] Make self-update more robust In fact, the old method was unsafe. Curl would modify the script in-place and there was no guarantee that the script is already in memory, leading to harmless, but unnecessary corruption at the end of the script. mv is atomic, so will unlink the old file before writing the new one. --- ghcup | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/ghcup b/ghcup index 9818ff1..6cb1446 100755 --- a/ghcup +++ b/ghcup @@ -696,10 +696,11 @@ self_update() { status_message "Updating ${SCRIPT}" ( - edo cd "${target_location}" - + edo cd "$(mktemp -d)" edo download "${SCRIPT_UPDATE_URL}" - edo chmod +x "${target_location}"/ghcup + edo chmod +x ghcup + edo mv -f ghcup "${target_location}"/ghcup + ) || die "failed to install" status_message "Done, make sure \"${target_location}\" is in your PATH!"