You are not logged in.

#1 2020-05-02 19:45:25

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Detecting cyclically dependent "orphan" packages.

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

#2 2020-05-03 00:28:18

zenbum
Member
From: California
Registered: 2020-02-29
Posts: 8

Re: Detecting cyclically dependent "orphan" packages.

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

#3 2020-05-03 01:26:15

Trilby
Inspector Parrot
Registered: 2011-11-29
Posts: 29,442
Website

Re: Detecting cyclically dependent "orphan" packages.

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

Board footer

Powered by FluxBB