diff options
-rw-r--r-- | rust.eselect.in | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/rust.eselect.in b/rust.eselect.in index 02f7b75..d0f3361 100644 --- a/rust.eselect.in +++ b/rust.eselect.in @@ -10,6 +10,28 @@ BIN_DIR="${EROOT%/}/usr/bin" inherit package-manager path-manipulation +# find a list of missing or broken symlinks +# each compiler installs a list of provided programs. +# this function checks if a symlink for a provided program +# is missing or broken for the current active Rust implementation +find_missing_broken_symlinks() { + local -a missing_symlinks + local required_symlinks=( "/usr/bin/rustc" $(get_last_set_symlinks) ) + + for i in "${required_symlinks[@]}"; do + local symlink="${EROOT%/}${i}" + + if [[ -L "${symlink}" && -e "${symlink}" ]]; then + # existing symlink + continue + else + missing_symlinks+=( "${symlink}" ) + fi + done + + echo "${missing_symlinks[@]}" +} + # find a list of installed rust compilers # each compiler provider should install # a config file named provider-$pkgname-$pkgver @@ -219,8 +241,13 @@ do_update() { shift done - if [[ "${if_unset}" == "1" && -f "${BIN_DIR}/rustc" ]]; then - return + if [[ "${if_unset}" == "1" ]]; then + local missing_symlinks=( $(find_missing_broken_symlinks) ) + if [[ ${#missing_symlinks[@]} -eq 0 ]]; then + return + else + echo "Not all symlinks set. Will switch to the most recent Rust compiler!" + fi fi local targets=( $(find_targets) ) @@ -251,8 +278,13 @@ do_unset() { shift done - if [[ "${if_invalid}" == "1" && -e "${BIN_DIR}/rustc" ]]; then - return + if [[ "${if_invalid}" == "1" ]]; then + local missing_symlinks=( $(find_missing_broken_symlinks) ) + if [[ ${#missing_symlinks[@]} -eq 0 ]]; then + return + else + echo "Not all symlinks set. Will unset current symlinked Rust binaries!" + fi fi unset_version || die -q "Couldn't unset active version" |