You are not logged in.
Pages: 1
Topic closed
I just noted, while testing a PKGBUILD for another thread, that `makepkg -s` installed several dependencies to build the package in question. But after working with it for a bit, I did my normal routine to remove those no-longer needed dependencies. They should all be orphans as I did not install the built package and they were installed "--as-deps". But nothing was removed with `pacman -Qdttq | pacman -Rsn -`.
I realized that there was a dependency cycle among these --as-deps packages, so pacman didn't list them as actual orphans. These were the package: ruby, ruby-irb, ruby-reline, rubygems
I could remove them with `pacman -Rsn ruby`, but then I double checked the following:
$ pacman -Q ruby
error: package 'ruby' was not found
$ sudo pacman -S --asdeps ruby
...
$ pacman -Qdtq
Again, while I can easily remove all these packages by removing ruby, it occurred to me that there may be other similarly installed packages for which I have no use but they are maintaining themselves as dependencies. I am curious if there is a way to detect these "leaf cycles" with pacman. I have the following script as a first pass which gets the job done, but I'm wondering if there'd be a better approach:
#!/bin/sh
pacman -Qdq | while read pkg; do
pactree -lr $pkg | pacman -Qe - >/dev/null || echo $pkg
done
One incremental improvement would be if there was a way for pacman to list any dependency cycles - this would greatly reduce the candidate list to check in the above loop.
-----------
EDIT: second pass, the following is much more efficient (8 times faster on my machine):
#!/bin/sh
pacman -Qeq | while read pkg; do
pactree -lu $pkg
done | sort -u > /tmp/needed.pkg
pacman -Qq | comm -23 - /tmp/needed.pkg
Note: bash users could avoid the tmp file with process substitution (untested):
#!/bin/bash
pacman -Qeq | while read pkg; do
pactree -lu $pkg
done | sort -u | comm -23 <(pacman -Qq) -
-----
EDIT: third pass, the bottle neck of the previous version can be helped a bit with xargs - though I'm pretty new to using xargs so this may need feedback. On my system this is twice as fast as the previous verion:
#!/bin/sh
pacman -Qeq | \
xargs -I PKG -P $(nproc) pactree -lu PKG | \
sort -u > /tmp/needed.pkg
pacman -Qq | sort -u | comm -23 - /tmp/needed.pkg
Last edited by Trilby (2020-05-03 01:26:34)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
Looks like you're onto something very useful.
When I run your script, comm complains:
$ pacman -Qq | comm -23 - /tmp/needed.pkg
comm: file 1 is not in sorted order
I wonder if that line should be changed to:
$ pacman -Qq | sort -u | comm -23 - /tmp/needed.pkg
Offline
Ah, yes, it should. Odd that it never complained for me. I just checked, while I don't know there is assurance that it should be, my `pacman -Qq` is already in order.
(edit: I do set LC_COLLATE=C, but I tried unsetting this, and my pacman -Qq output is still always in sorted order. Certainly it's not that important, but I am curious why this would differ between our systems.)
Last edited by Trilby (2020-05-11 12:54:38)
"UNIX is simple and coherent" - Dennis Ritchie; "GNU's Not Unix" - Richard Stallman
Offline
https://wiki.archlinux.org/title/Pacman … d_packages wrote
pacman -Qqd | pacman -Rsu --print -
can be used to detect and print those orphan dependency cycles and other more unneeded packages. So
pacman -Qqd | sudo pacman -Rsu -
should be able to remove them. I tested with it and it successfully detects and removes some of my orphan dependency cycles and excessive dependencies packages.
Offline
Thanks for the relevant contribution, but seeing as the topic is over 4 years old, I'm going to close it.
https://wiki.archlinux.org/title/Genera … bumping%22
Closing.
Offline
too slow
Last edited by Lone_Wolf (2025-05-17 13:19:10)
Disliking systemd intensely, but not satisfied with alternatives so focusing on taming systemd.
clean chroot building not flexible enough ?
Try clean chroot manager by graysky
Offline
Pages: 1
Topic closed