1 |
commit: 64844b8bf854a1651efb7e0d0473e808a0f5aa8b |
2 |
Author: Aaron W. Swenson <titanofold <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat May 21 13:22:24 2016 +0000 |
4 |
Commit: Aaron Swenson <titanofold <AT> gentoo <DOT> org> |
5 |
CommitDate: Sat May 21 13:22:24 2016 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/postgresql/eselect.git/commit/?id=64844b8b |
7 |
|
8 |
Remove most/all active.links creation points |
9 |
|
10 |
Refactor do_set so that it doesn't create active.links* files. Will need |
11 |
to refactor unlinker and move its content into do_update. |
12 |
|
13 |
do_unset now does a lot more work to look for and remove symlinks |
14 |
managed by this module. |
15 |
|
16 |
postgresql.eselect | 100 ++++++++++++++++++++++++++++++++++++----------------- |
17 |
1 file changed, 68 insertions(+), 32 deletions(-) |
18 |
|
19 |
diff --git a/postgresql.eselect b/postgresql.eselect |
20 |
index 8d816dc..160e60e 100644 |
21 |
--- a/postgresql.eselect |
22 |
+++ b/postgresql.eselect |
23 |
@@ -13,6 +13,20 @@ B_PATH="${EROOT%/}/usr" |
24 |
E_PATH="${EROOT%/}/etc/eselect/postgresql" |
25 |
ENV_FILE="${EROOT%/}/etc/env.d/50postgresql" |
26 |
|
27 |
+# This list of files/directories are the symbolic link targets that need to be |
28 |
+# created when a slot is set. |
29 |
+# |
30 |
+# If you change this list, remember to change include_sources in do_set. And, |
31 |
+# they must be listed in the same order. |
32 |
+INCLUDE_TARGETS=( |
33 |
+ "${B_PATH}"/include/postgresql |
34 |
+ "${B_PATH}"/include/libpq-fe.h |
35 |
+ "${B_PATH}"/include/pg_config_ext.h |
36 |
+ "${B_PATH}"/include/pg_config_manual.h |
37 |
+ "${B_PATH}"/include/libpq |
38 |
+ "${B_PATH}"/include/postgres_ext.h |
39 |
+) |
40 |
+ |
41 |
active_slot() { |
42 |
# ${B_PATH}/share/postgresql is a symlink. See if it's there, then |
43 |
# find out where it links to |
44 |
@@ -40,6 +54,8 @@ lib_dir() { |
45 |
fi |
46 |
} |
47 |
|
48 |
+### TODO: Refactor to move find into a separate function |
49 |
+ |
50 |
### Linker Function ### |
51 |
# Takes four arguments: |
52 |
# - Full source path (e.g. /usr/lib/postgresql-9.0/lib) |
53 |
@@ -75,10 +91,12 @@ linker() { |
54 |
# root if $ROOT is not "/". |
55 |
rel_source=$(relative_name "${link_source}" "${target_dir}") |
56 |
ln -s "${rel_source}" "${link_target}" || die -q "Unable to create link!" |
57 |
- echo "${link_target##${ROOT%/}/}" >> "${E_PATH}"/active.links${suffix} |
58 |
done |
59 |
} |
60 |
|
61 |
+### TODO: Refactor so that it searches source directories for removal targets, |
62 |
+### and move the old stuff into do_update |
63 |
+ |
64 |
### Unlinker Function ### |
65 |
# Takes one argument: |
66 |
# - Full path to active links file (e.g. /etc/eselect/postgresql/active.links) |
67 |
@@ -181,20 +199,31 @@ describe_set() { |
68 |
|
69 |
do_set() { |
70 |
local SLOT=$1 |
71 |
+ |
72 |
if [[ ! -d ${B_PATH}/$(lib_dir)/postgresql-${SLOT} ]] ; then |
73 |
die -q "Not a valid slot." |
74 |
fi |
75 |
|
76 |
- echo "Setting ${SLOT} as the default installation..." |
77 |
+ # If there's an active slot, unset that one first |
78 |
+ if [[ "$(active_slot)" == "${SLOT}" ]] ; then |
79 |
+ echo $(highlight "No work to do.") |
80 |
+ echo "If you think the links need to be reset, use the reset action." |
81 |
+ return 0 |
82 |
+ elif [[ "$(active_slot)" != "(none)" ]] ; then |
83 |
+ echo -ne "\tRemoving old links..." |
84 |
+ do_unset $(active_slot) |
85 |
+ echo "done." |
86 |
+ fi |
87 |
|
88 |
- # Remove the active links to start a fresh list |
89 |
- echo -ne "\tRemoving old links..." |
90 |
- unlinker ${E_PATH}/active.links |
91 |
- echo "done." |
92 |
+ echo "Setting ${SLOT} as the default installation..." |
93 |
|
94 |
echo -ne "\tGenerating new links..." |
95 |
- # Sources and targets for header files |
96 |
- local sources=( |
97 |
+ # Sources for header files |
98 |
+ # Targets are listed in the global variable INCLUDE_TARGETS. |
99 |
+ # |
100 |
+ # If you change this list, you must change the INCLUDE_TARGETS list, |
101 |
+ # too. And, they must be listed in the same order. |
102 |
+ local include_sources=( |
103 |
"${B_PATH}"/include/postgresql-${SLOT} |
104 |
"${B_PATH}"/include/postgresql-${SLOT}/libpq-fe.h |
105 |
"${B_PATH}"/include/postgresql-${SLOT}/pg_config_ext.h |
106 |
@@ -202,35 +231,20 @@ do_set() { |
107 |
"${B_PATH}"/include/postgresql-${SLOT}/libpq |
108 |
"${B_PATH}"/include/postgresql-${SLOT}/postgres_ext.h |
109 |
) |
110 |
- local targets=( |
111 |
- "${B_PATH}"/include/postgresql |
112 |
- "${B_PATH}"/include/libpq-fe.h |
113 |
- "${B_PATH}"/include/pg_config_ext.h |
114 |
- "${B_PATH}"/include/pg_config_manual.h |
115 |
- "${B_PATH}"/include/libpq |
116 |
- "${B_PATH}"/include/postgres_ext.h |
117 |
- ) |
118 |
|
119 |
# The linker function cannot accomadate this special purpose. |
120 |
local rel_source |
121 |
local i |
122 |
- for (( i=0; $i < ${#sources[@]}; i++ )) ; do |
123 |
- # Remove target before creating the symlink |
124 |
- [[ -h ${targets[$i]} ]] && rm -f "${targets[$i]}" |
125 |
- |
126 |
- # Check if link_target still exists |
127 |
- [[ -e ${targets[$i]} ]] && \ |
128 |
- die -q "The target '${targets[$i]}' exists and could not be removed!" |
129 |
- |
130 |
+ for (( i=0; $i < ${#include_sources[@]}; i++ )) ; do |
131 |
# Some headers are present only in specific versions of PostgreSQL |
132 |
- [[ -e ${sources[$i]} ]] || continue |
133 |
+ [[ -e ${include_sources[$i]} ]] || continue |
134 |
|
135 |
# Create relative links so that they work both here and inside the new |
136 |
# root if $ROOT is not "/" |
137 |
- rel_source=$(relative_name "${sources[$i]}" "$(dirname "${targets[$i]}")") |
138 |
+ rel_source=$(relative_name "${include_sources[$i]}" "$(dirname "${INCLUDE_TARGETS[$i]}")") |
139 |
|
140 |
- ln -s "$rel_source" "${targets[$i]}" || die -q "Unable to create link!" |
141 |
- echo "${targets[$i]##${ROOT%/}/}" >> "${E_PATH}"/active.links |
142 |
+ ln -s "$rel_source" "${INCLUDE_TARGETS[$i]}" || \ |
143 |
+ die -q "Unable to create link!" |
144 |
done |
145 |
|
146 |
# Link modules to /usr/lib{,32,64}/ |
147 |
@@ -240,8 +254,7 @@ do_set() { |
148 |
# 'linker' function doesn't work for linking directories. |
149 |
# Default lib path - create a relative link |
150 |
ln -s "postgresql-${SLOT}/${x}" "${B_PATH}/${x}/postgresql" |
151 |
- echo "${B_PATH##${ROOT%/}/}/${x}/postgresql" >> \ |
152 |
- "${E_PATH}"/active.links |
153 |
+ |
154 |
# Linker works for files |
155 |
linker "${B_PATH}/${x}/postgresql-${SLOT}/${x}/" \ |
156 |
"-name lib*" "${B_PATH}/${x}" |
157 |
@@ -255,7 +268,6 @@ do_set() { |
158 |
# Default share path - use a relative link here by just specifying the |
159 |
# base name |
160 |
ln -s "postgresql-${SLOT}" "${B_PATH}/share/postgresql" |
161 |
- echo "${B_PATH##${ROOT%/}/}/share/postgresql" >> "${E_PATH}/active.links" |
162 |
|
163 |
echo "done." |
164 |
echo "Setting ${SLOT} as default was successful!" |
165 |
@@ -266,17 +278,41 @@ describe_unset() { |
166 |
echo "Remove symbolic links." |
167 |
} |
168 |
|
169 |
+# Undo everything done by do_set(). |
170 |
do_unset() { |
171 |
local SLOT=$1 |
172 |
if [[ ${SLOT} = $(active_slot) ]] ; then |
173 |
echo -n "Unsetting ${SLOT} as the default installation..." |
174 |
- unlinker "${E_PATH}/active.links" |
175 |
+ |
176 |
echo "done." |
177 |
echo "Setting a new slot as the default." |
178 |
do_update |
179 |
else |
180 |
echo "Inactive slot selected. No work to do." |
181 |
fi |
182 |
+ |
183 |
+ local l |
184 |
+ for l in ${INCLUDE_TARGETS[@]} "${B_PATH}/share/postgresql" ; do |
185 |
+ # Remove target before creating the symlink |
186 |
+ [[ -h ${l} ]] && rm -f "${l}" |
187 |
+ |
188 |
+ # Check if include target still exists |
189 |
+ [[ -e ${l} ]] && \ |
190 |
+ die -q "The target '${l}' exists and could not be removed!" |
191 |
+ done |
192 |
+ |
193 |
+ for x in $(list_libdirs) ; do |
194 |
+ if [[ -d ${B_PATH}/${x}/postgresql-${SLOT}/${x} ]] ; then |
195 |
+ if [[ -h "${B_PATH}/${x}/postgresql" ]] ; then |
196 |
+ rm -f "${B_PATH}/${x}/postgresql" |
197 |
+ [[ -e "${B_PATH}/${x}/postgresql" ]] && \ |
198 |
+ die -q "Unable to remove '${B_PATH}/${x}/postgresql'" |
199 |
+ fi |
200 |
+ |
201 |
+ unlinker "${B_PATH}/${x}/postgresql-${SLOT}/${x}/" \ |
202 |
+ "-name lib*" "${B_PATH}/${x}" |
203 |
+ fi |
204 |
+ done |
205 |
} |
206 |
|
207 |
### Reset Action ### |