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.
This commit is contained in:
2018-10-08 22:42:04 +08:00
parent 54c42c7718
commit 2193b42822

7
ghcup
View File

@@ -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!"