commit: 7190ae6e3da59f7390b0e00081594d672bffc0db Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org> AuthorDate: Wed May 18 19:10:19 2016 +0000 Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org> CommitDate: Wed May 18 19:10:19 2016 +0000 URL: https://gitweb.gentoo.org/proj/postgresql/eselect.git/commit/?id=7190ae6e
Stateless: No longer rely on an 'active' file Working towards a stateless module, no need to keep track of links or active slot in a collection of files. /usr/share/postgresql is symbolic link generated by this module. So, we're able to determine which real directory it's pointing to, which will be /usr/share/postgresql-SLOT. A bit of sed magic gets just the slot portion off the end. Et voila! We no longer need to store the active slot in a file. If /usr/share/postgresql doesn't exist, then we haven't set a slot. postgresql.eselect | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/postgresql.eselect b/postgresql.eselect index 6468ab6..1e9ff3b 100644 --- a/postgresql.eselect +++ b/postgresql.eselect @@ -14,8 +14,11 @@ E_PATH="${EROOT%/}/etc/eselect/postgresql" ENV_FILE="${EROOT%/}/etc/env.d/50postgresql" active_slot() { - if [[ -r ${E_PATH}/active && -n ${E_PATH}/active ]] ; then - echo $( <"${E_PATH}"/active ) + # ${B_PATH}/share/postgresql is a symlink. See if it's there, then + # find out where it links to + if [[ -h "${B_PATH}/share/postgresql" ]] ; then + canonicalise "${B_PATH}/share/postgresql" | \ + sed 's|.*postgresql-\([1-9][0-9.]*\)|\1|' else echo "(none)" fi @@ -246,7 +249,6 @@ do_set() { ln -s "postgresql-${SLOT}" "${B_PATH}/share/postgresql" echo "${B_PATH##${ROOT%/}/}/share/postgresql" >> "${E_PATH}/active.links" - echo ${SLOT} > "${E_PATH}/active" echo "done." echo "Setting ${SLOT} as default was successful!" } @@ -261,7 +263,6 @@ do_unset() { if [[ ${SLOT} = $(active_slot) ]] ; then echo -n "Unsetting ${SLOT} as the default installation..." unlinker "${E_PATH}/active.links" - rm -f "${E_PATH}/active" echo "done." echo "Setting a new slot as the default." do_update @@ -289,13 +290,13 @@ describe_update() { do_update() { local slot=$(active_slot) - # Check for files managed by postgresql.eselect before 1.0 - if [[ -h ${E_PATH}/active ]] ; then - slot="$(basename $(canonicalise ${E_PATH}/active)))" - rm -f "${E_PATH}/active" - fi - # Remove service file outright. - [[ -h ${E_PATH}/service ]] && rm -f "${E_PATH}/service" + + # Remove some files outright as they're entirely useless now. + local f + for f in "${E_PATH}/active" "${E_PATH}/service"; do + [[ -e "${f}" ]] && rm -f "${f}" + done + local slots=($(get_slots)) local index=${#slots[@]} @@ -313,7 +314,6 @@ do_update() { for sym_links in "${E_PATH}"/active.links* ; do unlinker "${sym_links}" done - rm -f "${E_PATH}/active" rm -f "${ENV_FILE}" do_action env update &> /dev/null echo "Done!"