From 58a7e85534f260a49a324dd5b3f408ce1e21cd18 Mon Sep 17 00:00:00 2001 From: Aurelien Foret Date: Thu, 16 Feb 2006 21:02:39 +0000 Subject: - db_write: add support to write both local and sync entries - code cleanup --- lib/libalpm/alpm.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'lib/libalpm/alpm.c') 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); } -- cgit v1.2.3-24-g4f1b