You are not logged in.

#1 2005-04-29 15:14:26

loserMcloser
Member
From: Canada
Registered: 2004-12-15
Posts: 121

pacman -Qo

I have found pacman -Qo <filename> to often return no or incorrect results, (or maybe I misunderstand its function), so here is a simple bash script that takes a filename as argument and tells you which package installed that file. It's quite slow, but it works.  Hope you find it useful.

#!/bin/sh

get_full_path()
{
    # arg1: filename
    # arg2: name of return variable
    if [ $# -lt 2 ]
    then
        return
    fi
    _PWD=`pwd`
    _DIR=`dirname $1`
    _FILE=`basename $1`
    cd $_DIR
    eval "$2=`pwd`/${_FILE}"
    cd $_PWD
}


###############
# main

if [ $# != 1 ]
then
    echo
    echo "Usage: findfileowner <file>"
    exit 2
fi

FILE=""
get_full_path $1 FILE

if [ ! -f $FILE ]
then
    echo
    echo "File does not exist"
    exit 2
fi

count=0

for P in `pacman -Q`
do
    if [ $count = 0 ]
    then
        OWNER=`pacman -Ql $P | grep $FILE`
        if [ $? = 0 ]
        then
            OWNER=`echo $OWNER | cut -d " " -f 1`
            echo
            echo "$FILE was installed by $OWNER"
            exit 0
        fi
        count=1
    else
        count=0
    fi
done

echo
echo "File not found"
exit 1

Offline

#2 2005-04-29 15:28:30

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: pacman -Qo

I don't think I understand what's going on - you say "pacman -Qo" returns nothing, but you're still using pacman to determine the owner...

pacman -Qo works fine for me...

Offline

#3 2005-04-29 15:41:09

loserMcloser
Member
From: Canada
Registered: 2004-12-15
Posts: 121

Re: pacman -Qo

I'm still using pacman to find the file, but what I've found is that pacman -Qo and pacman -Ql don't always agree, at least not on my system. Or, as I said in the original post, maybe I misunderstand what "owner" of a file means. But here is an example:

[username@hostname:~]
[1]% pacman -Qo /etc/zsh/zprofile       
/etc/zsh/zprofile is owned by bash 3.0-6

[username@hostname:~]
[2]% pacman -Ql bash | grep "/etc/zsh/zprofile"                                          

[username@hostname:~]
[3]% pacman -Ql zsh | grep "/etc/zsh/zprofile"
zsh /etc/zsh/zprofile

Offline

#4 2005-04-29 15:49:26

phrakture
Arch Overlord
From: behind you
Registered: 2003-10-29
Posts: 7,879
Website

Re: pacman -Qo

huh, I've never come across something like that... I'd submit a bug report...

nice script though!

Offline

Board footer

Powered by FluxBB