You are not logged in.

#1 2008-02-06 12:34:52

drf
Member
From: Milano, Italy
Registered: 2008-01-13
Posts: 113

Some alpm questions

Hey everyone
I have some question on libalpm, I hope someone can give me answers:

First: is there a fast way, given a pmpkg_t *, to see if it is installed? Using alpm_pkg_get_reason or get_install_date is extremely slow.

Second: is current design of question handling ever going to change? At the current status, the only way I could make it work showing the user a popup dialog asking for its answer was by freezing libalpm thread.

Thanks in advance

Offline

#2 2008-02-06 12:53:19

drf
Member
From: Milano, Italy
Registered: 2008-01-13
Posts: 113

Re: Some alpm questions

Sorry, ignore the first question, they're not slow smile

Offline

#3 2008-02-06 13:03:15

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 9,939
Website

Re: Some alpm questions

First: To quickly find if a package is installed you could use alpm_db_get_pkg.  I think this returns NULL if the package is not install.  I am still getting my head around some of the code so could be wrong....

Edit: They may not be slow but it seems my response was though.....

Last edited by Allan (2008-02-06 13:04:11)

Offline

#4 2008-02-06 13:18:19

drf
Member
From: Milano, Italy
Registered: 2008-01-13
Posts: 113

Re: Some alpm questions

@allan lol anyway, with alpm_db_get_pkg on local database, I think you retrieve not only installed packages, but also packages in cache that are not installed (e.g.: packages you have removed but that have been kept on your HD). I could be wrong though...

Offline

#5 2008-02-06 13:21:42

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Some alpm questions

drf wrote:

Hey everyone
I have some question on libalpm, I hope someone can give me answers:

First: is there a fast way, given a pmpkg_t *, to see if it is installed? Using alpm_pkg_get_reason or get_install_date is extremely slow.

Second: is current design of question handling ever going to change? At the current status, the only way I could make it work showing the user a popup dialog asking for its answer was by freezing libalpm thread.

Thanks in advance

Firstly, you will probably find more people with some knowledge of libalpm on pacman-dev mailing list (don't worry, Allan is there too wink).
Secondly, the easiest way to find out how to use libalpm currently is probably to look at the reference implementation that is pacman.
For example, you might know that pacman -Q <package> returns if a package is installed or not.

So you look at src/pacman/query.c , pacman_query function, lines ~400, and see :
pkg = alpm_db_get_pkg(db_local, strname);

Same for the questions handling stuff and all other callbacks from libalpm, have a look at src/pacman/callback.c :
lines ~254 :
/* callback to handle questions from libalpm transactions (yes/no) */

(hmm, with all the TODO there, you might want to consider improving libalpm before writing a frontend wink but it might be possible to do both in parallel)


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#6 2008-02-06 13:22:37

Allan
Developer
From: Brisbane, AU
Registered: 2007-06-09
Posts: 9,939
Website

Re: Some alpm questions

I'm pretty sure alpm_db_get_pkg is what gets called when you "pacman -Q <pkg>" so should return things from the cache...

Offline

#7 2008-02-06 13:25:02

shining
Pacman Developer
Registered: 2006-05-10
Posts: 2,043

Re: Some alpm questions

drf wrote:

@allan lol anyway, with alpm_db_get_pkg on local database, I think you retrieve not only installed packages, but also packages in cache that are not installed (e.g.: packages you have removed but that have been kept on your HD). I could be wrong though...

Hm, yes you are wink
/var/lib/pacman/local and /var/cache/pacman/pkg are two different things.

However, the internal representation of /var/lib/pacman/local in libalpm is also called a (package) cache indeed, because it keeps in memory (at least the time of a libalpm session) informations that are on the filesystem.


pacman roulette : pacman -S $(pacman -Slq | LANG=C sort -R | head -n $((RANDOM % 10)))

Offline

#8 2008-02-06 13:35:08

drf
Member
From: Milano, Italy
Registered: 2008-01-13
Posts: 113

Re: Some alpm questions

Great, thanks a lot to both of you!
I'll probably drop some messages on the list then wink
Cheers

Last edited by drf (2008-02-06 13:37:03)

Offline

Board footer

Powered by FluxBB