commit:     00c695d6152bb8f2e7a288a5c019986ed3ee9495
Author:     Daniel Verkamp <dverkamp <AT> chromium <DOT> org>
AuthorDate: Fri Sep  7 23:28:32 2018 +0000
Commit:     Mike Frysinger <vapier <AT> gentoo <DOT> org>
CommitDate: Fri Dec 22 05:31:16 2023 +0000
URL:        https://gitweb.gentoo.org/proj/pax-utils.git/commit/?id=00c695d6

lddtree: use readlink -f for absolute links

Commit b97eba7fb2c0a3c5ad9e3831c6f87dca1fde59c5 causes problems when
using lddtree with symlinks containing absolute paths, such as the
crosvm guest tools, which install these links:

  /usr/bin/sommelier -> /etc/alternatives/sommelier ->
  /opt/google/cros-containers/bin/sommelier

(where the final sommelier is the lddtree-generated script).

In this case, $base resolved by the lddtree script would be
'/usr/bin//etc/alternatives/sommelier', which is incorrect.

Replace the dirname/readlink combination with readlink -f when the
symlink is absolute in order to fully resolve the symlink, while keeping
the relative path when the script is invoked through a relative path.

Bug: https://crbug.com/882055
Signed-off-by: Daniel Verkamp <dverkamp <AT> chromium.org>
Signed-off-by: Mike Frysinger <vapier <AT> chromium.org>
Signed-off-by: Mike Frysinger <vapier <AT> gentoo.org>

 lddtree.py | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/lddtree.py b/lddtree.py
index bbf9df9..8184e8f 100755
--- a/lddtree.py
+++ b/lddtree.py
@@ -187,7 +187,13 @@ def GenerateLdsoWrapper(
     # remove absolute paths from build outputs and enables directory 
independent
     # cache sharing in distributed build systems.
     wrapper = """#!/bin/sh
-if ! base=$(dirname "$0")/$(readlink "$0" 2>/dev/null); then
+if base=$(readlink "$0" 2>/dev/null); then
+  # If $0 is an abspath symlink, fully resolve the target.
+  case ${base} in
+  /*) base=$(readlink -f "$0" 2>/dev/null);;
+  *)  base=$(dirname "$0")/${base};;
+  esac
+else
   case $0 in
   /*) base=$0;;
   *)  base=${PWD:-`pwd`}/$0;;

Reply via email to