summaryrefslogtreecommitdiff
path: root/lib/libalpm/db.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2007-05-31 02:51:28 -0400
committerDan McGee <dan@archlinux.org>2007-05-31 02:51:28 -0400
commit7bd2ff685188d0d9b6ab6c6f43f6d28811936881 (patch)
tree30bbb96d2bbb8a6c63d9f7e7e6ac1c8b4b818148 /lib/libalpm/db.c
parent722db4535ae6690d8834ffebf3a0de3a880188f9 (diff)
Move DB and cache dirs away from there dependence on ROOTDIR
This change allows us to use all autoconf specified paths, most notably $(localstatedir). It is quite a change and touches a lot of files, as all references to the DB and cache were done with the ROOTDIR as a prefix. * add --lock command-line option to pacman to specify the location of the lockfile (this can now be specified at configure time by setting the $localstatedir path). * Rip quite a few settings out of configure.ac as they are now picked by setting the paths during configure or make. * Fix bug with /tmp fallback for sync downloads not working correctly (related to root location, now the system tmp dir is used). * Simplified the parameters to some libalpm functions, and added get/set for the new lockfile option. * Renamed several of the DEFS to names without the PM_ prefix. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/db.c')
-rw-r--r--lib/libalpm/db.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/lib/libalpm/db.c b/lib/libalpm/db.c
index a1c1121d..0aa8de18 100644
--- a/lib/libalpm/db.c
+++ b/lib/libalpm/db.c
@@ -52,9 +52,10 @@
#include "cache.h"
#include "alpm.h"
-pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
+pmdb_t *_alpm_db_new(const char *dbpath, const char *treename)
{
pmdb_t *db;
+ const size_t pathsize = strlen(dbpath) + strlen(treename) + 2;
ALPM_LOG_FUNC;
@@ -65,14 +66,14 @@ pmdb_t *_alpm_db_new(const char *root, const char *dbpath, const char *treename)
RET_ERR(PM_ERR_MEMORY, NULL);
}
- db->path = calloc(1, strlen(root)+strlen(dbpath)+strlen(treename)+2);
+ db->path = calloc(1, pathsize);
if(db->path == NULL) {
_alpm_log(PM_LOG_ERROR, _("malloc failed: could not allocate %d bytes"),
- strlen(root)+strlen(dbpath)+strlen(treename)+2);
+ pathsize);
FREE(db);
RET_ERR(PM_ERR_MEMORY, NULL);
}
- sprintf(db->path, "%s%s%s/", root, dbpath, treename);
+ sprintf(db->path, "%s%s/", dbpath, treename);
strncpy(db->treename, treename, PATH_MAX);
@@ -160,6 +161,7 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
{
struct stat buf;
pmdb_t *db;
+ const char *dbpath;
char path[PATH_MAX];
ALPM_LOG_FUNC;
@@ -183,15 +185,17 @@ pmdb_t *_alpm_db_register(const char *treename, alpm_cb_db_register callback)
_alpm_log(PM_LOG_DEBUG, _("registering database '%s'"), treename);
/* make sure the database directory exists */
- snprintf(path, PATH_MAX, "%s%s/%s", handle->root, handle->dbpath, treename);
+ dbpath = alpm_option_get_dbpath();
+ snprintf(path, PATH_MAX, "%s%s", dbpath, treename);
if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
- _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"), path);
+ _alpm_log(PM_LOG_DEBUG, _("database directory '%s' does not exist, creating it"),
+ path);
if(_alpm_makepath(path) != 0) {
RET_ERR(PM_ERR_SYSTEM, NULL);
}
}
- db = _alpm_db_new(handle->root, handle->dbpath, treename);
+ db = _alpm_db_new(handle->dbpath, treename);
if(db == NULL) {
RET_ERR(PM_ERR_DB_CREATE, NULL);
}