tech-toolchain archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

Re: is "postinstall fix obsolete" supposed to clean out /usr/lib?



On Tue, Jun 03, 2025 at 03:08:04 +0300, Valery Ushakov wrote:

> When we have a library in /lib we also has symlinks in /usr/lib.
> Among others we have the symlink for the actually DSO binary:
> 
>     /usr/lib/libfoo.so.1.0 -> ../../lib/libfoo.so.1.0
> 
> But exclude_libs naively/conservatively chops symlink targets to just
> the basename, so from the above symlink it concludes that
> libfoo.so.1.0 has something that points to it, never mind that that
> libfoo.so.1.0 is actually in /lib, not in /usr/lib.  And so
> exclude_libs thinks the /usr/lib/libfoo.so.1.0 is not obsolete and
> should be excluded from the purge.

Something like this, perhaps?  It deletes quasi self-referencing links
from the consideration.  This probably can be rewritten back to use
'+' to ammortize exec costs, but I didn't want the extra loop to
obscure the already elaborate expression in this example:

--- a/postinstall
+++ b/postinstall
@@ -595,8 +595,11 @@
 #
 exclude_libs()
 {
-	local targets="$(find lib*.so.* -prune -type l -exec readlink '{}' + 2> /dev/null \
-	    | ${SED} -e 's@.*/@@' | ${SORT} -u)"
+	local targets="$(find lib*.so.* -prune 2> /dev/null		 \
+		-type l -exec sh -c					 \
+			'printf "%s " "$1"; basename "$(readlink "$1")"' \
+				-- '{}' ';'				 \
+	    | ${AWK} '$1 != $2 { print $2 }' | ${SORT} -u)"
 	${GREP} -F -v -x "$targets"
 }

-uwe


Home | Main Index | Thread Index | Old Index