You are not logged in.
This is why I wish there was an actual API reference for ALPM instead of forcing developers to fend for themselves in a near-undocumented mess of a library.
That said, I need some help. I have the correct #includes in my code:
#include <alpm.h>
#include <alpm_list.h>
But apparently the compiler can't see what is supposed to be provided by the very first (I think?) header. My source is simple right now since I've mostly just begun my project:
#include <alpm.h>
#include <alpm_list.h>
#include "../function/pacman.h"
bool initALPM()
{
if(alpm_initialize()<0)
{
return false;
}
alpm_option_set_dbpath("/var/lib/pacman");
db = alpm_db_register_local();
return true;
}
bool releaseALPM()
{
if(alpm_release()<0)
{
return false;
}
return true;
}
std::vector<std::string> getPackageList()
{
std::vector<pmdb_t*> sync;
pmdb_t* local;
std::vector<std::string> packs;
return packs;
}Any idea what I'm doing wrong in this? For all I can figure, I *should not* be having troubles with my compiler finding that function.
Also, any hint as to how I could get a list of "sync" databases?
Offline
If you were still able to find that function, you'd be using pacman 3.4. alpm_db_register_local was removed for 3.5.0. If you read the patch notes, you'll see that alpm_initialize() takes care of that for you. I'm also not sure how well alpm will play with c++ since it doesn't have the extern "C" decl in the header...
By default, no syncs are registered. pacman parses its own config file and registers the DBs it finds declared there with alpm. An example in C...
#include <stdio.h>
#include <alpm.h>
static const char *trees[] = {
"testing",
"core",
"extra",
"community",
NULL
};
int main(void) {
const char **tree;
pmdb_t *local;
alpm_list_t *i;
/* initialize -- this registers localdb for you */
alpm_initialize();
/* barebones setup */
alpm_option_set_root("/");
alpm_option_set_dbpath("/var/lib/pacman");
/* register syncs */
for (tree = trees; *tree; tree++) {
alpm_db_register_sync(*tree);
}
/* iterate over registered syncs */
printf("--- sync DBs -----------------\n");
for (i = alpm_option_get_syncdbs(); i; i = alpm_list_next(i)) {
pmdb_t *sync = alpm_list_getdata(i);
printf("%s\n", alpm_db_get_name(sync));
}
putchar('\n');
/* iterate over local database */
printf("--- local packages -----------\n");
local = alpm_option_get_localdb();
for (i = alpm_db_get_pkgcache(local); i; i = alpm_list_next(i)) {
pmpkg_t *pkg = alpm_list_getdata(i);
printf("%s\n", alpm_pkg_get_name(pkg));
}
putchar('\n');
/* cleanup */
alpm_release();
return 0;
}Last edited by falconindy (2011-04-10 03:08:29)
Offline
If you were still able to find that function, you'd be using pacman 3.4. alpm_db_register_local was removed for 3.5.0. If you read the patch notes, you'll see that alpm_initialize() takes care of that for you. I'm also not sure how well alpm will play with c++ since it doesn't have the extern "C" decl in the header...
By default, no syncs are registered. pacman parses its own config file and registers the DBs it finds declared there with alpm. An example in C...
snip
Ah, that would explain it. I still see the functions in libalpm's source from the ABS, but I am on the latest pacman. So I automatically have my sync db's "registered?"
How do I get a list of packages in all dbs, including local?
I wonder if it might be easier to just make my package manager just issue shell commands instead of using alpm.
Offline
No. your local is registered automatically. You see the source of that function because it still exists, its just not made public. You need to register sync DBs on your own, likely through some sort of config file. There's enough in my example to show how to iterate over the packages in a pmdb_t* whether its a sync or a local.
Last edited by falconindy (2011-04-10 03:27:36)
Offline
No. your local is registered automatically. You see the source of that function because it still exists, its just not made public. You need to register sync DBs on your own, likely through some sort of config file. There's enough in my example to show how to iterate over the packages in a pmdb_t* whether its a sync or a local.
Thanks. Now I just gotta figure out a good way to parse configs. I'm debating between sticking with pacman's configuration or try out my own.
Offline
There's a problem with your code snippet. I'm getting:
/home/yaro/projects/pullstring-build-desktop/../pullstring/src/function/pacman.cpp:46: error: invalid conversion from ‘void*’ to ‘pmdb_t*’
Offline
There's a problem with your code snippet. I'm getting:
/home/yaro/projects/pullstring-build-desktop/../pullstring/src/function/pacman.cpp:46: error: invalid conversion from ‘void*’ to ‘pmdb_t*’
No, there is a problem in assuming perfectly valid and correct C is valid C++ code. Please do some thinking on your own or you are just going to scare away anyone from trying to help you...
Offline
Yaro wrote:There's a problem with your code snippet. I'm getting:
/home/yaro/projects/pullstring-build-desktop/../pullstring/src/function/pacman.cpp:46: error: invalid conversion from ‘void*’ to ‘pmdb_t*’
No, there is a problem in assuming perfectly valid and correct C is valid C++ code. Please do some thinking on your own or you are just going to scare away anyone from trying to help you...
Then help me figure out how to do it in C++. Not my fault the Arch devs seem to have a phobia of doing any decent API documentation for ALPM.
Offline
Thanks to another developer who uses Archlinux, he told me I needed to explicitly cast the conversion myself. Thanks to those who helped me.
Offline