commit: 1ce72c8f890d9effe502d6d103bca10c6e4b56c4 Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org> AuthorDate: Fri Jul 21 18:31:29 2017 +0000 Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org> CommitDate: Fri Jul 21 18:31:29 2017 +0000 URL: https://gitweb.gentoo.org/proj/postgresql/eselect.git/commit/?id=1ce72c8f
Canonicalise even if nonexistent canoncalise() returns the absolute path a symbolic link points to, except when the path no longer exists. Adding the -m option – which is the same for both realpath and readlink – makes it ignore nonexistent portions of the path. Bug: https://bugs.gentoo.org/625368 postgresql.eselect | 25 ++++++++++++++++--------- 1 file 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
