You are not logged in.

#1 2011-08-12 12:59:12

dkremer
Member
Registered: 2011-08-10
Posts: 15

Check concordance between the package database and the filesystem

Hello, I'd like to write this down :

To list the packages installed in the database, I use

pacman -Qsq

-Q because it's a query on the local database, s to search and q for quiet.

If you would like to list the files installed by pacman on your computer, you would do

pacman  -Qqs | xargs pacman -Ql | cut -f2 -d' '

and if you would to count them you could write

pacman -Qqs|xargs pacman -Ql|wc -l

If you'd want to know if the files actually exist, and reporting for errors, you could run

for a_package in $(pacman  -Qqs) ; do  
    for a_file in $( pacman -Ql ${a_package}|cut -d' ' -f2 ) ; do 
        if [ ! -e ${a_file} ]; then 
            echo package ${a_package} is broken: file ${a_file} is missing. ;
            # use the following if you would wish to remove the broken package.
            # sudo pacman -R ${a_package} ;
            # break
        fi ;  
    done ;  
done

The if test does check if the file, whatever its kind (folder, symbolic link, etc), does actually exist on your computer, and report a problem if the file is missing. In a generality purpose, I used test -e. You could look at the test manpage, to look for more elaborate examples. You can imagine report what kind of file is missing, or run a check of the permissions and owner which file has in the file system.

So, I use this because I recently messed up my system with AUR build that came along with the database, but was hard to debug. I don't know how to distinguish between an AUR package and an official package, so this solution came out to clean my database.

I hope I could post more code snippets here if you find it useful. See you.

Last edited by dkremer (2011-08-12 13:05:26)

Offline

#2 2011-08-12 13:04:47

Allan
Pacman
From: Brisbane, AU
Registered: 2007-06-09
Posts: 11,672
Website

Re: Check concordance between the package database and the filesystem

pacman -Qk ?

Offline

#3 2011-08-12 13:15:15

dkremer
Member
Registered: 2011-08-10
Posts: 15

Re: Check concordance between the package database and the filesystem

Allan wrote:

pacman -Qk ?

yes. It does the job as well. Just a question: can you use the output of this command to remove the packages which are broken ?

EDIT: actually pacman -Qqk gives the name of broken packages. My apologies.

Last edited by dkremer (2011-08-14 13:20:23)

Offline

Board footer

Powered by FluxBB