diff options
author | 2016-05-18 15:10:19 -0400 | |
---|---|---|
committer | 2016-05-18 15:10:19 -0400 | |
commit | 7190ae6e3da59f7390b0e00081594d672bffc0db (patch) | |
tree | fd62e5ea0ff3fcf3925b96a75b513455cb888edb | |
parent | We are removing symbolic links, not files. (diff) | |
download | eselect-7190ae6e3da59f7390b0e00081594d672bffc0db.tar.gz eselect-7190ae6e3da59f7390b0e00081594d672bffc0db.tar.bz2 eselect-7190ae6e3da59f7390b0e00081594d672bffc0db.zip |
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.
-rw-r--r-- | postgresql.eselect | 24 |
1 files 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!" |