commit:     99577f8e98440da176709b6e4b988b40ae42b8d1
Author:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
AuthorDate: Mon Mar 11 00:42:52 2019 +0000
Commit:     Thomas Deutschmann <whissi <AT> gentoo <DOT> org>
CommitDate: Mon Mar 11 04:54:36 2019 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-rust.git/commit/?id=99577f8e

Add and make use of find_missing_broken_symlinks()

dev-lang/rust or dev-lang/rust-bin install more than one binary (program),
just checking for "rustc" is not enough.

In addition, set of installed programs depends on USE flags.

This new (internal) function will check for all provided programs.

Bug: https://bugs.gentoo.org/671182
Signed-off-by: Thomas Deutschmann <whissi <AT> gentoo.org>

 rust.eselect.in | 40 ++++++++++++++++++++++++++++++++++++----
 1 file 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"

Reply via email to