Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-01-28 17:41:15 -0600
committerDan McGee <dan@archlinux.org>2011-01-29 12:13:56 -0600
commitef86da97f54a90ee4ba3ba8ea7963135e7bae8ed (patch)
tree99c492d170d3780ac2530413031593cc248a8fd3 /src
parent9b876fff09f2af10cba6824bec03d8fe3e167b5b (diff)
Remove need to explicitly register the local DB
Perform the cheap struct and string setup of the local DB at handle initialization time to match the teardown we do when releasing the handle. If the local DB is not needed, all real initialization is done lazily after DB paths and other things have been configured anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'src')
-rw-r--r--src/pacman/database.c4
-rw-r--r--src/pacman/pacman.c9
-rw-r--r--src/pacman/query.c11
-rw-r--r--src/pacman/remove.c2
-rw-r--r--src/pacman/sync.c11
-rw-r--r--src/util/pactree.c2
-rw-r--r--src/util/testdb.c2
7 files changed, 19 insertions, 22 deletions
diff --git a/src/pacman/database.c b/src/pacman/database.c
index 5fd33ea5..36433f33 100644
--- a/src/pacman/database.c
+++ b/src/pacman/database.c
@@ -31,8 +31,6 @@
#include "conf.h"
#include "util.h"
-extern pmdb_t *db_local;
-
/**
* @brief Modify the 'local' package database.
*
@@ -43,6 +41,7 @@ extern pmdb_t *db_local;
int pacman_database(alpm_list_t *targets)
{
alpm_list_t *i;
+ pmdb_t *db_local;
int retval = 0;
pmpkgreason_t reason;
@@ -65,6 +64,7 @@ int pacman_database(alpm_list_t *targets)
return(1);
}
+ db_local = alpm_option_get_localdb();
for(i = targets; i; i = alpm_list_next(i)) {
char *pkgname = i->data;
if(alpm_db_set_pkgreason(db_local, pkgname, reason) == -1) {
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c
index c2670604..45500cfb 100644
--- a/src/pacman/pacman.c
+++ b/src/pacman/pacman.c
@@ -57,7 +57,6 @@
#include "conf.h"
#include "package.h"
-pmdb_t *db_local;
/* list of targets specified on command line */
static alpm_list_t *pm_targets;
@@ -1433,14 +1432,6 @@ int main(int argc, char *argv[])
list_display("Targets :", pm_targets);
}
- /* Opening local database */
- db_local = alpm_db_register_local();
- if(db_local == NULL) {
- pm_printf(PM_LOG_ERROR, _("could not register 'local' database (%s)\n"),
- alpm_strerrorlast());
- cleanup(EXIT_FAILURE);
- }
-
/* Log commandline */
if(needs_root()) {
cl_to_log(argc, argv);
diff --git a/src/pacman/query.c b/src/pacman/query.c
index fc6a2a56..c79133d1 100644
--- a/src/pacman/query.c
+++ b/src/pacman/query.c
@@ -37,8 +37,6 @@
#include "conf.h"
#include "util.h"
-extern pmdb_t *db_local;
-
static char *resolve_path(const char *file)
{
char *str = NULL;
@@ -102,6 +100,7 @@ static int query_fileowner(alpm_list_t *targets)
char *append;
size_t max_length;
alpm_list_t *t;
+ pmdb_t *db_local;
/* This code is here for safety only */
if(targets == NULL) {
@@ -117,6 +116,8 @@ static int query_fileowner(alpm_list_t *targets)
append = path + strlen(path);
max_length = PATH_MAX - (append - path) - 1;
+ db_local = alpm_option_get_localdb();
+
for(t = targets; t; t = alpm_list_next(t)) {
char *filename, *dname, *rpath;
const char *bname;
@@ -220,6 +221,7 @@ static int query_search(alpm_list_t *targets)
{
alpm_list_t *i, *searchlist;
int freelist;
+ pmdb_t *db_local = alpm_option_get_localdb();
/* if we have a targets list, search for packages matching it */
if(targets) {
@@ -286,6 +288,8 @@ static int query_group(alpm_list_t *targets)
alpm_list_t *i, *j;
char *grpname = NULL;
int ret = 0;
+ pmdb_t *db_local = alpm_option_get_localdb();
+
if(targets == NULL) {
for(j = alpm_db_get_grpcache(db_local); j; j = alpm_list_next(j)) {
pmgrp_t *grp = alpm_list_getdata(j);
@@ -471,6 +475,7 @@ int pacman_query(alpm_list_t *targets)
int match = 0;
alpm_list_t *i;
pmpkg_t *pkg = NULL;
+ pmdb_t *db_local;
/* First: operations that do not require targets */
@@ -495,6 +500,8 @@ int pacman_query(alpm_list_t *targets)
}
}
+ db_local = alpm_option_get_localdb();
+
/* operations on all packages in the local DB
* valid: no-op (plain -Q), list, info, check
* invalid: isfile, owns */
diff --git a/src/pacman/remove.c b/src/pacman/remove.c
index 52f92ec0..82d1c384 100644
--- a/src/pacman/remove.c
+++ b/src/pacman/remove.c
@@ -31,8 +31,6 @@
#include "util.h"
#include "conf.h"
-extern pmdb_t *db_local;
-
/**
* @brief Remove a specified list of packages.
*
diff --git a/src/pacman/sync.c b/src/pacman/sync.c
index 278f15e5..7353f7ee 100644
--- a/src/pacman/sync.c
+++ b/src/pacman/sync.c
@@ -37,8 +37,6 @@
#include "package.h"
#include "conf.h"
-extern pmdb_t *db_local;
-
/* if keep_used != 0, then the db files which match an used syncdb
* will be kept */
static int sync_cleandb(const char *dbpath, int keep_used) {
@@ -144,6 +142,7 @@ static int sync_cleancache(int level)
{
alpm_list_t *i;
alpm_list_t *sync_dbs = alpm_option_get_syncdbs();
+ pmdb_t *db_local = alpm_option_get_localdb();
int ret = 0;
for(i = alpm_option_get_cachedirs(); i; i = alpm_list_next(i)) {
@@ -295,7 +294,7 @@ static int sync_synctree(int level, alpm_list_t *syncs)
return(success > 0);
}
-static void print_installed(pmpkg_t *pkg)
+static void print_installed(pmdb_t *db_local, pmpkg_t *pkg)
{
const char *pkgname = alpm_pkg_get_name(pkg);
const char *pkgver = alpm_pkg_get_version(pkg);
@@ -316,6 +315,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
alpm_list_t *i, *j, *ret;
int freelist;
int found = 0;
+ pmdb_t *db_local = alpm_option_get_localdb();
for(i = syncs; i; i = alpm_list_next(i)) {
pmdb_t *db = alpm_list_getdata(i);
@@ -366,7 +366,7 @@ static int sync_search(alpm_list_t *syncs, alpm_list_t *targets)
printf(")");
}
- print_installed(pkg);
+ print_installed(db_local, pkg);
/* we need a newline and initial indent first */
printf("\n ");
@@ -519,6 +519,7 @@ static int sync_info(alpm_list_t *syncs, alpm_list_t *targets)
static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
{
alpm_list_t *i, *j, *ls = NULL;
+ pmdb_t *db_local = alpm_option_get_localdb();
if(targets) {
for(i = targets; i; i = alpm_list_next(i)) {
@@ -556,7 +557,7 @@ static int sync_list(alpm_list_t *syncs, alpm_list_t *targets)
if (!config->quiet) {
printf("%s %s %s", alpm_db_get_name(db), alpm_pkg_get_name(pkg),
alpm_pkg_get_version(pkg));
- print_installed(pkg);
+ print_installed(db_local, pkg);
printf("\n");
} else {
printf("%s\n", alpm_pkg_get_name(pkg));
diff --git a/src/util/pactree.c b/src/util/pactree.c
index 0ac3f246..6a10006f 100644
--- a/src/util/pactree.c
+++ b/src/util/pactree.c
@@ -77,7 +77,7 @@ static int alpm_local_init(void)
return(ret);
}
- db_local = alpm_db_register_local();
+ db_local = alpm_option_get_localdb();
if(!db_local) {
return(1);
}
diff --git a/src/util/testdb.c b/src/util/testdb.c
index 96a123a6..461cf23a 100644
--- a/src/util/testdb.c
+++ b/src/util/testdb.c
@@ -136,7 +136,7 @@ static int check_localdb(void) {
return(ret);
}
- db = alpm_db_register_local();
+ db = alpm_option_get_localdb();
if(db == NULL) {
fprintf(stderr, "error: could not register 'local' database (%s)\n",
alpm_strerrorlast());