commit:     d5ad69d12994e69882830faae26ba565d8980a25
Author:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
AuthorDate: Sun Mar  1 12:53:47 2020 +0000
Commit:     Michael Orlitzky <mjo <AT> gentoo <DOT> org>
CommitDate: Sun Mar  1 12:59:07 2020 +0000
URL:        https://gitweb.gentoo.org/proj/eselect-php.git/commit/?id=d5ad69d1

src/php.eselect.in.in: only create links to targets that exist.

To avoid replacing a working /usr/bin/phar with a broken symlink,
let's check to make sure that the targets of our symlinks exist before
creating them. This can leave "phar" pointing to an unexpected version
of that executable, but that's better than nothing if some working
version is installed.

Signed-off-by: Michael Orlitzky <mjo <AT> gentoo.org>

 src/php.eselect.in.in | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/php.eselect.in.in b/src/php.eselect.in.in
index 2a7e5a8..d243c64 100644
--- a/src/php.eselect.in.in
+++ b/src/php.eselect.in.in
@@ -180,10 +180,9 @@ parse_target_major_version() {
 # working.
 #
 # There is one potential caveat to that approach, for SAPIs with more
-# than one active symlink. What if "phpize" is broken but "php" is OK?
-# (Forget for the moment how that might happen...). Do we want to
-# update() the entire SAPI because one of the symlinks is dead?
-# Answer: I guess.
+# than one active symlink. What if "phar" is broken (after a rebuild)
+# but "php" is OK? Do we want to update() the entire SAPI because one
+# of the symlinks is dead? Answer: I guess.
 #
 # INPUT:
 #
@@ -467,9 +466,19 @@ set_sapi() {
                local relative_target=$(relative_name \
                                                                        
"${link_tgt_dir}/${link_target}" \
                                                                        
"${link_dir}" )
-               # Use the short "-f" option for POSIX compatibility.
-               @LN_S@ -f "${relative_target}" "${link_dir}/${link_name}" || \
-                       die -q "failed to create active ${link_name} symlink"
+
+               # Since the phar extension is optional, we check here to
+               # ensure that the target of our symlink exists before we
+               # create it.  Otherwise, we could wind up with a /usr/bin/phar
+               # symlink that points nowhere. This might leave /usr/bin/phar
+               # pointing to a different version than you'd expect (wherever
+               # it pointed before you just tried to change it), but I guess
+               # leaving some working version is not a terrible thing to do.
+               if [[ -e "${link_tgt_dir}/${link_target}" ]]; then
+                       # Use the short "-f" option for POSIX compatibility.
+                       @LN_S@ -f "${relative_target}" 
"${link_dir}/${link_name}" || \
+                               die -q "failed to create active ${link_name} 
symlink"
+               fi
        done
 
        # The call to write_mod_php_conf() in particular needs to take

Reply via email to