@@ -455,27 +455,37 @@ install_package() {
455
455
fi
456
456
}
457
457
458
- rm -Rf " ${CFG_TMP_DIR} "
459
- need_ok " failed to remove temporary installation directory"
458
+ # It's possible that curl could be interrupted partway though downloading
459
+ # `rustup.sh`, truncating the file. This could be especially bad if we were in
460
+ # the middle of a line that would run "rm -rf ". To protect against this, we
461
+ # wrap up the `rustup.sh` destructive functionality in this helper function,
462
+ # which we call as the last thing we do. This means we will not do anything
463
+ # unless we have the entire file downloaded.
464
+ install_packages () {
465
+ rm -Rf " ${CFG_TMP_DIR} "
466
+ need_ok " failed to remove temporary installation directory"
460
467
461
- mkdir -p " ${CFG_TMP_DIR} "
462
- need_ok " failed to create create temporary installation directory"
463
-
464
- download_and_extract_package \
465
- " ${RUST_URL} " \
466
- " ${RUST_TARBALL_NAME} "
468
+ mkdir -p " ${CFG_TMP_DIR} "
469
+ need_ok " failed to create create temporary installation directory"
467
470
468
- if [ -z " ${CFG_DISABLE_CARGO} " ]; then
469
471
download_and_extract_package \
470
- " ${CARGO_URL} " \
471
- " ${CARGO_TARBALL_NAME} "
472
- fi
472
+ " ${RUST_URL} " \
473
+ " ${RUST_TARBALL_NAME} "
473
474
474
- install_package " ${RUST_LOCAL_INSTALL_SCRIPT} "
475
+ if [ -z " ${CFG_DISABLE_CARGO} " ]; then
476
+ download_and_extract_package \
477
+ " ${CARGO_URL} " \
478
+ " ${CARGO_TARBALL_NAME} "
479
+ fi
475
480
476
- if [ -z " ${CFG_DISABLE_CARGO} " ]; then
477
- install_package " ${CARGO_LOCAL_INSTALL_SCRIPT} "
478
- fi
481
+ install_package " ${RUST_LOCAL_INSTALL_SCRIPT} "
482
+
483
+ if [ -z " ${CFG_DISABLE_CARGO} " ]; then
484
+ install_package " ${CARGO_LOCAL_INSTALL_SCRIPT} "
485
+ fi
486
+
487
+ rm -Rf " ${CFG_TMP_DIR} "
488
+ need_ok " couldn't rm temporary installation directory"
489
+ }
479
490
480
- rm -Rf " ${CFG_TMP_DIR} "
481
- need_ok " couldn't rm temporary installation directory"
491
+ install_packages
0 commit comments