Skip to content

Commit 8ca8e6f

Browse files
committed
rustup: factor out installing packages into a function
1 parent b388dc6 commit 8ca8e6f

File tree

1 file changed

+14
-27
lines changed

1 file changed

+14
-27
lines changed

src/etc/rustup.sh

Lines changed: 14 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -443,6 +443,18 @@ download_and_extract_package() {
443443
fi
444444
}
445445

446+
# Wrap all the commands needed to install a package.
447+
install_package() {
448+
install_script="$1"
449+
450+
sh "${install_script}" "${CFG_INSTALL_FLAGS}"
451+
if [ $? -ne 0 ]
452+
then
453+
rm -Rf "${CFG_TMP_DIR}"
454+
err "failed to install Rust"
455+
fi
456+
}
457+
446458
rm -Rf "${CFG_TMP_DIR}"
447459
need_ok "failed to remove temporary installation directory"
448460

@@ -459,35 +471,10 @@ if [ -z "${CFG_DISABLE_CARGO}" ]; then
459471
"${CARGO_TARBALL_NAME}"
460472
fi
461473

462-
463-
(cd "${CFG_TMP_DIR}" && ${CFG_TAR} xzf "${RUST_TARBALL_NAME}")
464-
if [ $? -ne 0 ]
465-
then
466-
rm -Rf "${CFG_TMP_DIR}"
467-
err "failed to unpack installer"
468-
fi
469-
470-
sh "${RUST_LOCAL_INSTALL_SCRIPT}" "${CFG_INSTALL_FLAGS}"
471-
if [ $? -ne 0 ]
472-
then
473-
rm -Rf "${CFG_TMP_DIR}"
474-
err "failed to install Rust"
475-
fi
474+
install_package "${RUST_LOCAL_INSTALL_SCRIPT}"
476475

477476
if [ -z "${CFG_DISABLE_CARGO}" ]; then
478-
(cd "${CFG_TMP_DIR}" && ${CFG_TAR} xzf "${CARGO_TARBALL_NAME}")
479-
if [ $? -ne 0 ]
480-
then
481-
rm -Rf "${CFG_TMP_DIR}"
482-
err "failed to unpack cargo installer"
483-
fi
484-
485-
sh "${CARGO_LOCAL_INSTALL_SCRIPT}" "${CFG_INSTALL_FLAGS}"
486-
if [ $? -ne 0 ]
487-
then
488-
rm -Rf "${CFG_TMP_DIR}"
489-
err "failed to install Cargo"
490-
fi
477+
install_package "${CARGO_LOCAL_INSTALL_SCRIPT}"
491478
fi
492479

493480
rm -Rf "${CFG_TMP_DIR}"

0 commit comments

Comments
 (0)