summaryrefslogtreecommitdiff
path: root/lib/libalpm/alpm.c
diff options
context:
space:
mode:
authorAurelien Foret <aurelien@archlinux.org>2006-02-16 21:02:39 +0000
committerAurelien Foret <aurelien@archlinux.org>2006-02-16 21:02:39 +0000
commit58a7e85534f260a49a324dd5b3f408ce1e21cd18 (patch)
treef0b60c1c8a26a58400522ceee54fb908866a64a0 /lib/libalpm/alpm.c
parentdc0bacf18cfe2481516778905051879bd008f517 (diff)
downloadpacman-58a7e85534f260a49a324dd5b3f408ce1e21cd18.tar.xz
- db_write: add support to write both local and sync entries
- code cleanup
Diffstat (limited to 'lib/libalpm/alpm.c')
-rw-r--r--lib/libalpm/alpm.c12
1 files changed, 11 insertions, 1 deletions
diff --git a/lib/libalpm/alpm.c b/lib/libalpm/alpm.c
index 58474eb8..7ac7ada2 100644
--- a/lib/libalpm/alpm.c
+++ b/lib/libalpm/alpm.c
@@ -161,6 +161,8 @@ int alpm_get_option(unsigned char parm, long *data)
*/
pmdb_t *alpm_db_register(char *treename)
{
+ char path[PATH_MAX];
+ struct stat buf;
pmdb_t *db;
int found = 0;
@@ -187,7 +189,15 @@ pmdb_t *alpm_db_register(char *treename)
RET_ERR(PM_ERR_DB_NOT_NULL, NULL);
}
- db = db_open(handle->root, handle->dbpath, treename, DB_O_CREATE);
+ /* make sure the database directory exists */
+ snprintf(path, PATH_MAX, "%s%s", handle->root, handle->dbpath);
+ if(stat(path, &buf) != 0 || !S_ISDIR(buf.st_mode)) {
+ if(_alpm_makepath(path) != 0) {
+ RET_ERR(PM_ERR_SYSTEM, NULL);
+ }
+ }
+
+ db = db_open(path, treename, DB_O_CREATE);
if(db == NULL) {
RET_ERR(PM_ERR_DB_OPEN, NULL);
}