From eed808b53242071290c333c634efd7d42a5be2d7 Mon Sep 17 00:00:00 2001 From: Brian Anderson Date: Fri, 21 Mar 2014 20:12:51 -0700 Subject: [PATCH] install: Improve error handling --- src/etc/install.sh | 39 ++++++++++++++++++++++++++++----------- 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/src/etc/install.sh b/src/etc/install.sh index 5b41e25e257..63bb71558ab 100644 --- a/src/etc/install.sh +++ b/src/etc/install.sh @@ -224,13 +224,14 @@ step_msg "validating $CFG_SELF args" validate_opt # Sanity check: can we can write to the destination? -mkdir -p "${CFG_PREFIX}/lib" +umask 022 && mkdir -p "${CFG_PREFIX}/lib" +need_ok "directory creation failed" touch "${CFG_PREFIX}/lib/rust-install-probe" 2> /dev/null if [ $? -ne 0 ] then err "can't write to destination. try again with 'sudo'." fi -rm -r "${CFG_PREFIX}/lib/rust-install-probe" +rm "${CFG_PREFIX}/lib/rust-install-probe" need_ok "failed to remove install probe" # Sanity check: can we run these binaries? @@ -238,35 +239,51 @@ need_ok "failed to remove install probe" need_ok "can't run these binaries on this platform" -# First, uninstall from the installation prefix +# First, uninstall from the installation prefix. +# Errors are warnings - try to rm everything in the manifest even if some fail. # FIXME: Hardcoded 'rustlib' ignores CFG_RUSTLIBDIR if [ -f "${CFG_PREFIX}/lib/rustlib/manifest" ] then + # Iterate through installed manifest and remove files while read p; do - msg "uninstall ${CFG_PREFIX}/$p" - rm "${CFG_PREFIX}/$p" - need_ok "failed to remove file" + msg "removing ${CFG_PREFIX}/$p" + if [ -f "${CFG_PREFIX}/$p" ] + then + rm "${CFG_PREFIX}/$p" + if [ $? -ne 0 ] + then + warn "failed to remove ${CFG_PREFIX}/$p" + fi + else + warn "supposedly installed file ${CFG_PREFIX}/$p does not exist!" + fi done < "${CFG_PREFIX}/lib/rustlib/manifest" # Remove 'rustlib' directory - msg "uninstall ${CFG_PREFIX}/lib/rustlib" + msg "removing ${CFG_PREFIX}/lib/rustlib" rm -r "${CFG_PREFIX}/lib/rustlib" - need_ok "failed to remove rustlib" + if [ $? -ne 0 ] + then + warn "failed to remove rustlib" + fi else if [ -n "${CFG_UNINSTALL}" ] then - err "unable to find manifest at ${CFG_PREFIX}/lib/rustlib" - exit 0 + err "unable to find installation manifest at ${CFG_PREFIX}/lib/rustlib" fi fi # If we're only uninstalling then exit if [ -n "${CFG_UNINSTALL}" ] then + echo + echo " Rust is uninstalled. Have a nice day." + echo exit 0 fi -# Iterate through the new manifest and install files + +# Now install, iterate through the new manifest and copy files while read p; do umask 022 && mkdir -p "${CFG_PREFIX}/$(dirname $p)"