commit:     976d0542987023dfe6ba97e3e297c36e7317c1bd
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Fri Jan  8 18:33:08 2016 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Fri Jan  8 18:33:08 2016 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=976d0542

Refactor set_apache2() to use set_sapi().

With a little bit of mangling and a new (trivial) function, the
set_sapi() function now does the work of set_apache2(). There is
probably a better "big picture" to handle the symlinking, but this
works for now and is an improvement.

 src/php.eselect.in | 69 ++++++++++++++++++++++++++++++++++++++----------------
 1 file changed, 49 insertions(+), 20 deletions(-)

diff --git a/src/php.eselect.in b/src/php.eselect.in
index 2e9ec8d..1288669 100644
--- a/src/php.eselect.in
+++ b/src/php.eselect.in
@@ -38,6 +38,38 @@ sapi_active_link_names() {
 
 
 # Each SAPI provides a few (one or more) "active" links in a
+# predictable location. The target directory (where they point) is
+# fixed for a given SAPI, and this function returns it.
+#
+# The name "target" is unfortunate, but that's the terminology that
+# "ln" uses. The link_name is the name of the link on the filesystem,
+# and target is where it points.
+#
+# INPUT:
+#
+# The first parameter is the name of a SAPI. The second parameter is
+# the name of a target.
+#
+# OUTPUT:
+#
+# The directory to which the given SAPI's symlinks point. For example,
+# the "cli" sapi has three executable symlinks and all of them point
+# to executables in /usr/lib/phpX.Y/bin.
+#
+sapi_active_link_target_dir() {
+       local sapi="${1}"
+       local target="${2}"
+
+       local link_target_dir="${EROOT}$(get_active_libdir)/${target}/bin"
+       if [[ "${sapi}" == "apache2" ]] ; then
+               link_target_dir+="/../apache2"
+       fi
+
+       echo "${link_target_dir}"
+}
+
+
+# Each SAPI provides a few (one or more) "active" links in a
 # predictable location. And fortunately that location is fixed for a
 # given SAPI. For example, the "cgi" SAPI has its sole active symlink,
 # /usr/bin/php-cgi, in /usr/bin. Given a SAPI name, we return the
@@ -390,34 +422,31 @@ set_sapi() {
        local target_name=$(resolv_target "${sapi}" "${target}")
        [[ -z $target_name ]] && die -q "invalid target ${target} for SAPI 
${sapi}"
 
-       local link_src_dir="../..$(get_active_libdir)/${target_name}/bin"
-       local link_dst_dir=$(sapi_active_link_dir "${sapi}")
+       local link_tgt_dir=$(sapi_active_link_target_dir "${sapi}" 
"${target_name}")
+       local link_dir=$(sapi_active_link_dir "${sapi}")
 
        for link_name in $(sapi_active_link_names "${sapi}"); do
-               @LN_S@ --force "${link_src_dir}/${link_name}" \
-                       "${link_dst_dir}/${link_name}" || \
+               # Usually the link targets have the same name as the link 
itself...
+               local link_target="${link_name}"
+
+               if [[ "${link_name}" == "mod_php.so" ]] ; then
+                  # ...but apache2 needs special handling since we're not
+                  # linking from something named mod_php.so.
+                  local major=$(parse_target_major_version "${target_name}")
+                  link_target="libphp${major}.so"
+               fi
+
+               @LN_S@ --force "${link_tgt_dir}/${link_target}" \
+                       "${link_dir}/${link_name}" || \
                        die -q "failed to create active ${link_name} symlink"
        done
 }
 
 
 set_apache2() {
-       local active_symlink libdir major target=$(resolv_target apache2 $1)
-       active_symlink="$(sapi_active_link_path apache2)"
-       major=$(parse_target_major_version "${target}")
-
-       [[ -z $target ]] && die -q "invalid target"
-
-       for libdir in $(get_libdirs); do
-               rm --force "${active_symlink}" || \
-                       die "failed to remove active module symlink"
-
-               @LN_S@ --force "../../${target}/apache2/libphp${major}.so" \
-                       "${active_symlink}" || \
-                       die -q "failed to create active mod_php symlink"
-       done
-
-       write_mod_php_conf "${target}"
+       local target="${1}"
+       set_sapi apache2 "${target}"
+       write_mod_php_conf "$(resolv_target apache2 "${target}")"
        echo "Please restart apache for the changes to take effect."
 }
 

Reply via email to