diff options
-rw-r--r-- | postgresql.eselect | 25 |
1 files changed, 16 insertions, 9 deletions
diff --git a/postgresql.eselect b/postgresql.eselect index 9203a97..84d08af 100644 --- a/postgresql.eselect +++ b/postgresql.eselect @@ -30,7 +30,7 @@ active_slot() { # ${USR_PATH}/share/postgresql is a symlink to the active # slot. See if it's there, then find out where it links to. if [[ -h "${USR_PATH}/share/postgresql" ]] ; then - canonicalise "${USR_PATH}/share/postgresql" | \ + canonicalise -m "${USR_PATH}/share/postgresql" | \ sed -re 's#.*([1-9][0-9.]+)$#\1#' else echo "(none)" @@ -283,6 +283,17 @@ do_unset() { return 0 fi + # Get the file path that the link is pointing to. If it has the string + # "postgresql-${slot}" somewhere in it, then it's a link that this module is + # handling. + is_slot_link() { + if [[ $(canonicalise -m "$1") == *postgresql-${slot}* ]] ; then + return 0 # yes + else + return 1 # no + fi + } + # Start with some known locations that are, or will contain, symlinks. local paths=( "${INCLUDE_TARGETS[@]}" @@ -307,10 +318,9 @@ do_unset() { local l path for path in "${paths[@]}" ; do - # If path is a link that belongs to the slot in question, it can be - # removed without invoking find. - if [[ -h "${path}" && \ - $(canonicalise "${path}") == *postgresql-${slot}* ]] ; then + # If $path is a link that belongs to the active slot, it can be removed + # without invoking find. + if [[ -h "${path}" ]] && is_slot_link "${path}" ; then rm "${path}" || write_warning_msg "Couldn't remove: ${path}" continue fi @@ -322,10 +332,7 @@ do_unset() { [[ ${l} == ${USR_PATH}/bin/*${slot/.} ]] && continue [[ ${l} == ${USR_PATH}/share/man/man?/*${slot/.}* ]] && continue - # Get the file path that the link is pointing to. If it has the - # string "postgresql-${slot}" somewhere in it, then it's a link that - # needs to be removed. - if [[ $(canonicalise "${l}") == *postgresql-${slot}* ]] ; then + if is_slot_link "${l}" ; then rm "${l}" || write_warning_msg "Couldn't remove: ${l}" fi done |