aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAaron W. Swenson <titanofold@gentoo.org>2016-08-08 18:35:42 -0400
committerAaron W. Swenson <titanofold@gentoo.org>2016-08-08 18:35:42 -0400
commit1fcb1813d38b60ab79556bf8bc1d464bbeec467e (patch)
tree3b5dcbbd71bbe7323cf7947cbf6703c7026f1493
parentRemove most/all active.links creation points (diff)
downloadeselect-1fcb1813d38b60ab79556bf8bc1d464bbeec467e.tar.gz
eselect-1fcb1813d38b60ab79556bf8bc1d464bbeec467e.tar.bz2
eselect-1fcb1813d38b60ab79556bf8bc1d464bbeec467e.zip
Refactor update to clean out old files and directories that are no longer used.
-rw-r--r--postgresql.eselect118
1 files changed, 65 insertions, 53 deletions
diff --git a/postgresql.eselect b/postgresql.eselect
index 160e60e..8463344 100644
--- a/postgresql.eselect
+++ b/postgresql.eselect
@@ -54,6 +54,23 @@ lib_dir() {
fi
}
+### Finder Function ###
+# Takes two arguments:
+# - Absolute path to directory to search
+# - Pattern to search for
+finder() {
+ local source_dir=$1
+ local pattern=$2
+
+ # Prevent passed patterns from being globbed
+ # If this module is run in /usr, '-name lib*' ends up globbing 'lib*',
+ # passing to 'find' the pattern '-name lib lib32 lib64' and find interprets
+ # those as path arguments causing failure.
+ set -f
+ find -L "${source_dir}" -maxdepth 1 -mindepth 1 ${pattern}
+ set +f
+}
+
### TODO: Refactor to move find into a separate function
### Linker Function ###
@@ -71,13 +88,7 @@ linker() {
local findings
local rel_source
- # Prevent passed patterns from being globbed
- # If this module is run in /usr, '-name lib*' ends up globbing 'lib*',
- # passing to 'find' the pattern '-name lib lib32 lib64' and find interprets
- # those as path arguments causing failure.
- set -f
- findings=$(find -L "${source_dir}" -maxdepth 1 -mindepth 1 ${pattern})
- set +f
+ findings=$(finder "${source_dir}" ${pattern})
for link_source in ${findings} ; do
local link_target="${target_dir%/}/$(basename ${link_source})${suffix}"
@@ -101,18 +112,10 @@ linker() {
# Takes one argument:
# - Full path to active links file (e.g. /etc/eselect/postgresql/active.links)
unlinker() {
- local active_link_file=$1
- if [[ -r ${active_link_file} ]] ; then
- local active_links=($(<"${active_link_file}"))
- for (( i=0; $i < ${#active_links[@]}; i++ )) ; do
- [[ -h "${ROOT%/}/${active_links[$i]}" ]] && \
- rm -f "${ROOT%/}/${active_links[$i]}"
- [[ -e "${ROOT%/}/${active_links[$i]}" ]] && \
- die -q "The target '${active_links[$i]}' still exists and could not be removed!"
- done
+ local dir
+ local pattern
+ local findings
- rm -f "${active_link_file}"
- fi
}
### Get Slots Function ###
@@ -335,54 +338,70 @@ describe_update() {
do_update() {
local slot=$(active_slot)
- # Remove some files outright as they're entirely useless now.
- # ${E_PATH}/active: Contents was the active slot (e.g., 9.5)
- # ${E_PATH}/service: Told the initscript which slot to start
- local f
- for f in "${E_PATH}/active" "${E_PATH}/service" ; do
- [[ -e "${f}" ]] && rm -f "${f}"
- done
+ ## CLEAN UP ##
+ #
+ # Older versions of this module generated state and environment files of
+ # some sort or another. They're useless now and are just a waste of space.
+ # Remove environment files that have been generated by the ebuilds
+ rm -f "${ENV_FILE}"-*
+
+ if [[ -d ${E_PATH} ]] ; then
+ # Remove some files outright as they're entirely useless now.
+ # ${E_PATH}/active: Contents was the active slot (e.g., 9.5)
+ # ${E_PATH}/service: Told the initscript which slot to start
+ local f
+ for f in "${E_PATH}/active" "${E_PATH}/service" ; do
+ [[ -e "${f}" ]] && rm -f "${f}"
+ done
+
+ local active_link_file
+ for active_link_file in "${E_PATH}"/active.links* ; do
+ local active_links=($(<"${active_link_file}"))
+ for (( i=0; $i < ${#active_links[@]}; i++ )) ; do
+ [[ -h "${ROOT%/}/${active_links[$i]}" ]] && \
+ rm -f "${ROOT%/}/${active_links[$i]}"
+ [[ -e "${ROOT%/}/${active_links[$i]}" ]] && \
+ die -q "The target '${active_links[$i]}' still exists and could not be removed!"
+ done
+
+ rm "${active_link_file}" || \
+ write_warning_msg "Can't remove '${active_link_file}'"
+ done
+
+ local unused_files
+ unused_file=$(find "${E_PATH}" -type f -not -name '.keep*')
+ if [[ -n "${unused_file[@]}" ]] ; then
+ write_warning_msg "You have unused files that should be removed:"
+ for f in ${unused_file[@]} ; do
+ write_warning_msg $f
+ done
+ else
+ echo "It's should be safe for you to remove '${E_PATH}'"
+ fi
+ fi
+ ## End Clean Up
local slots=($(get_slots))
local index=${#slots[@]}
- # In case all slots have been unmerged
if [[ ${index} -eq 0 ]] ; then
write_warning_msg "No slots found!"
- write_warning_msg "Removing links (Control-C to abort) in..."
- local i=6
- while [[ $[i--] -gt 0 ]] ; do
- echo -n " $i"
- sleep 1
- done
- local sym_links
- for sym_links in "${E_PATH}"/active.links* ; do
- unlinker "${sym_links}"
- done
rm -f "${ENV_FILE}"
do_action env update &> /dev/null
- echo "Done!"
return 0
fi
# Reset, otherwise set the highest slot available.
if [[ ${slots[@]} =~ ${slot} ]] ; then
- do_set ${slot}
+ do_reset ${slot}
else
# best_version doesn't work here as pkg_postrm runs before the world
# file is updated, thereby returning a false positive.
do_set ${slots[$index-1]}
fi
- echo -en "\nCleaning out old links before refreshing..."
- local sym_links
- for sym_links in "${E_PATH}"/active.links?* ; do
- unlinker "${sym_links}"
- done
- echo "done."
-
- # Update paths to libs and docs
+ # Update paths to libs and man pages
local ldpath
local x
for x in $(list_libdirs) ; do
@@ -393,22 +412,15 @@ do_update() {
local manpath="${B_PATH}/share/postgresql/man/"
while [[ $[--index] -gt -1 ]] ; do
local curslot="${slots[$index]}"
- echo -n "Refreshing symbolic links for ${curslot} applications (like "
- echo -n "/usr/bin/psql${curslot//.})..."
for x in $(list_libdirs) ; do
local lib_path="${B_PATH}/${x}/postgresql-${curslot}/${x}/"
[[ -d ${lib_path} ]] && ldpath+=":${lib_path}"
done
local tmp_manpath="${B_PATH}/share/postgresql-${curslot}/man/"
[[ -d ${tmp_manpath} ]] && manpath+=":${tmp_manpath}"
- linker "${B_PATH}/$(lib_dir)/postgresql-${curslot}/bin/" \
- "-type f" "${B_PATH}/bin" "${curslot//.}"
echo "done."
done
- # Remove environment files that have been generated by the ebuilds
- rm -f "${ENV_FILE}"-*
-
store_config "${ENV_FILE}" LDPATH "${ldpath}"
store_config "${ENV_FILE}" MANPATH "${manpath}"
do_action env update &> /dev/null