1 |
commit: 1fcb1813d38b60ab79556bf8bc1d464bbeec467e |
2 |
Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org> |
3 |
AuthorDate: Mon Aug 8 22:35:42 2016 +0000 |
4 |
Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org> |
5 |
CommitDate: Mon Aug 8 22:35:42 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/postgresql/eselect.git/commit/?id=1fcb1813 |
7 |
|
8 |
Refactor update to clean out old files and directories that are no longer used. |
9 |
|
10 |
postgresql.eselect | 118 +++++++++++++++++++++++++++++------------------------ |
11 |
1 file changed, 65 insertions(+), 53 deletions(-) |
12 |
|
13 |
diff --git a/postgresql.eselect b/postgresql.eselect |
14 |
index 160e60e..8463344 100644 |
15 |
--- a/postgresql.eselect |
16 |
+++ b/postgresql.eselect |
17 |
@@ -54,6 +54,23 @@ lib_dir() { |
18 |
fi |
19 |
} |
20 |
|
21 |
+### Finder Function ### |
22 |
+# Takes two arguments: |
23 |
+# - Absolute path to directory to search |
24 |
+# - Pattern to search for |
25 |
+finder() { |
26 |
+ local source_dir=$1 |
27 |
+ local pattern=$2 |
28 |
+ |
29 |
+ # Prevent passed patterns from being globbed |
30 |
+ # If this module is run in /usr, '-name lib*' ends up globbing 'lib*', |
31 |
+ # passing to 'find' the pattern '-name lib lib32 lib64' and find interprets |
32 |
+ # those as path arguments causing failure. |
33 |
+ set -f |
34 |
+ find -L "${source_dir}" -maxdepth 1 -mindepth 1 ${pattern} |
35 |
+ set +f |
36 |
+} |
37 |
+ |
38 |
### TODO: Refactor to move find into a separate function |
39 |
|
40 |
### Linker Function ### |
41 |
@@ -71,13 +88,7 @@ linker() { |
42 |
local findings |
43 |
local rel_source |
44 |
|
45 |
- # Prevent passed patterns from being globbed |
46 |
- # If this module is run in /usr, '-name lib*' ends up globbing 'lib*', |
47 |
- # passing to 'find' the pattern '-name lib lib32 lib64' and find interprets |
48 |
- # those as path arguments causing failure. |
49 |
- set -f |
50 |
- findings=$(find -L "${source_dir}" -maxdepth 1 -mindepth 1 ${pattern}) |
51 |
- set +f |
52 |
+ findings=$(finder "${source_dir}" ${pattern}) |
53 |
|
54 |
for link_source in ${findings} ; do |
55 |
local link_target="${target_dir%/}/$(basename ${link_source})${suffix}" |
56 |
@@ -101,18 +112,10 @@ linker() { |
57 |
# Takes one argument: |
58 |
# - Full path to active links file (e.g. /etc/eselect/postgresql/active.links) |
59 |
unlinker() { |
60 |
- local active_link_file=$1 |
61 |
- if [[ -r ${active_link_file} ]] ; then |
62 |
- local active_links=($(<"${active_link_file}")) |
63 |
- for (( i=0; $i < ${#active_links[@]}; i++ )) ; do |
64 |
- [[ -h "${ROOT%/}/${active_links[$i]}" ]] && \ |
65 |
- rm -f "${ROOT%/}/${active_links[$i]}" |
66 |
- [[ -e "${ROOT%/}/${active_links[$i]}" ]] && \ |
67 |
- die -q "The target '${active_links[$i]}' still exists and could not be removed!" |
68 |
- done |
69 |
+ local dir |
70 |
+ local pattern |
71 |
+ local findings |
72 |
|
73 |
- rm -f "${active_link_file}" |
74 |
- fi |
75 |
} |
76 |
|
77 |
### Get Slots Function ### |
78 |
@@ -335,54 +338,70 @@ describe_update() { |
79 |
do_update() { |
80 |
local slot=$(active_slot) |
81 |
|
82 |
- # Remove some files outright as they're entirely useless now. |
83 |
- # ${E_PATH}/active: Contents was the active slot (e.g., 9.5) |
84 |
- # ${E_PATH}/service: Told the initscript which slot to start |
85 |
- local f |
86 |
- for f in "${E_PATH}/active" "${E_PATH}/service" ; do |
87 |
- [[ -e "${f}" ]] && rm -f "${f}" |
88 |
- done |
89 |
+ ## CLEAN UP ## |
90 |
+ # |
91 |
+ # Older versions of this module generated state and environment files of |
92 |
+ # some sort or another. They're useless now and are just a waste of space. |
93 |
+ # Remove environment files that have been generated by the ebuilds |
94 |
+ rm -f "${ENV_FILE}"-* |
95 |
+ |
96 |
+ if [[ -d ${E_PATH} ]] ; then |
97 |
+ # Remove some files outright as they're entirely useless now. |
98 |
+ # ${E_PATH}/active: Contents was the active slot (e.g., 9.5) |
99 |
+ # ${E_PATH}/service: Told the initscript which slot to start |
100 |
+ local f |
101 |
+ for f in "${E_PATH}/active" "${E_PATH}/service" ; do |
102 |
+ [[ -e "${f}" ]] && rm -f "${f}" |
103 |
+ done |
104 |
+ |
105 |
+ local active_link_file |
106 |
+ for active_link_file in "${E_PATH}"/active.links* ; do |
107 |
+ local active_links=($(<"${active_link_file}")) |
108 |
+ for (( i=0; $i < ${#active_links[@]}; i++ )) ; do |
109 |
+ [[ -h "${ROOT%/}/${active_links[$i]}" ]] && \ |
110 |
+ rm -f "${ROOT%/}/${active_links[$i]}" |
111 |
+ [[ -e "${ROOT%/}/${active_links[$i]}" ]] && \ |
112 |
+ die -q "The target '${active_links[$i]}' still exists and could not be removed!" |
113 |
+ done |
114 |
+ |
115 |
+ rm "${active_link_file}" || \ |
116 |
+ write_warning_msg "Can't remove '${active_link_file}'" |
117 |
+ done |
118 |
+ |
119 |
+ local unused_files |
120 |
+ unused_file=$(find "${E_PATH}" -type f -not -name '.keep*') |
121 |
+ if [[ -n "${unused_file[@]}" ]] ; then |
122 |
+ write_warning_msg "You have unused files that should be removed:" |
123 |
+ for f in ${unused_file[@]} ; do |
124 |
+ write_warning_msg $f |
125 |
+ done |
126 |
+ else |
127 |
+ echo "It's should be safe for you to remove '${E_PATH}'" |
128 |
+ fi |
129 |
+ fi |
130 |
|
131 |
+ ## End Clean Up |
132 |
|
133 |
local slots=($(get_slots)) |
134 |
local index=${#slots[@]} |
135 |
|
136 |
- # In case all slots have been unmerged |
137 |
if [[ ${index} -eq 0 ]] ; then |
138 |
write_warning_msg "No slots found!" |
139 |
- write_warning_msg "Removing links (Control-C to abort) in..." |
140 |
- local i=6 |
141 |
- while [[ $[i--] -gt 0 ]] ; do |
142 |
- echo -n " $i" |
143 |
- sleep 1 |
144 |
- done |
145 |
- local sym_links |
146 |
- for sym_links in "${E_PATH}"/active.links* ; do |
147 |
- unlinker "${sym_links}" |
148 |
- done |
149 |
rm -f "${ENV_FILE}" |
150 |
do_action env update &> /dev/null |
151 |
- echo "Done!" |
152 |
return 0 |
153 |
fi |
154 |
|
155 |
# Reset, otherwise set the highest slot available. |
156 |
if [[ ${slots[@]} =~ ${slot} ]] ; then |
157 |
- do_set ${slot} |
158 |
+ do_reset ${slot} |
159 |
else |
160 |
# best_version doesn't work here as pkg_postrm runs before the world |
161 |
# file is updated, thereby returning a false positive. |
162 |
do_set ${slots[$index-1]} |
163 |
fi |
164 |
|
165 |
- echo -en "\nCleaning out old links before refreshing..." |
166 |
- local sym_links |
167 |
- for sym_links in "${E_PATH}"/active.links?* ; do |
168 |
- unlinker "${sym_links}" |
169 |
- done |
170 |
- echo "done." |
171 |
- |
172 |
- # Update paths to libs and docs |
173 |
+ # Update paths to libs and man pages |
174 |
local ldpath |
175 |
local x |
176 |
for x in $(list_libdirs) ; do |
177 |
@@ -393,22 +412,15 @@ do_update() { |
178 |
local manpath="${B_PATH}/share/postgresql/man/" |
179 |
while [[ $[--index] -gt -1 ]] ; do |
180 |
local curslot="${slots[$index]}" |
181 |
- echo -n "Refreshing symbolic links for ${curslot} applications (like " |
182 |
- echo -n "/usr/bin/psql${curslot//.})..." |
183 |
for x in $(list_libdirs) ; do |
184 |
local lib_path="${B_PATH}/${x}/postgresql-${curslot}/${x}/" |
185 |
[[ -d ${lib_path} ]] && ldpath+=":${lib_path}" |
186 |
done |
187 |
local tmp_manpath="${B_PATH}/share/postgresql-${curslot}/man/" |
188 |
[[ -d ${tmp_manpath} ]] && manpath+=":${tmp_manpath}" |
189 |
- linker "${B_PATH}/$(lib_dir)/postgresql-${curslot}/bin/" \ |
190 |
- "-type f" "${B_PATH}/bin" "${curslot//.}" |
191 |
echo "done." |
192 |
done |
193 |
|
194 |
- # Remove environment files that have been generated by the ebuilds |
195 |
- rm -f "${ENV_FILE}"-* |
196 |
- |
197 |
store_config "${ENV_FILE}" LDPATH "${ldpath}" |
198 |
store_config "${ENV_FILE}" MANPATH "${manpath}" |
199 |
do_action env update &> /dev/null |