summaryrefslogtreecommitdiffstats
path: root/lib/libalpm/alpm.c
diff options
context:
space:
mode:
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);
}