summaryrefslogtreecommitdiff
path: root/lib/libalpm
diff options
context:
space:
mode:
authorAllan McRae <allan@archlinux.org>2014-09-22 21:12:04 +1000
committerAllan McRae <allan@archlinux.org>2014-09-23 21:25:45 +1000
commitd3f5ab0e706071b8724575eb356b865d55da8df6 (patch)
tree6abf5ef5ded2311d8baef0dda09f237c7135dee1 /lib/libalpm
parent793b9c3b42c1af9b18a3cc8d08dd058f9cb96d93 (diff)
downloadpacman-d3f5ab0e706071b8724575eb356b865d55da8df6.tar.xz
Create local database directory if it is missing
This means that a missing local database becomes an error (as it should be immediately created). Note this only creates the "local" directory and not its parent, which is checked for during locking. Signed-off-by: Allan McRae <allan@archlinux.org>
Diffstat (limited to 'lib/libalpm')
-rw-r--r--lib/libalpm/be_local.c40
1 files changed, 26 insertions, 14 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 9a9bdef6..8c8b9b15 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -366,6 +366,16 @@ static int is_dir(const char *path, struct dirent *entry)
return 0;
}
+static int local_db_create(alpm_db_t *db, const char *dbpath)
+{
+ if(mkdir(dbpath, 0755) != 0) {
+ _alpm_log(db->handle, ALPM_LOG_ERROR, _("could not create directory %s: %s\n"),
+ dbpath, strerror(errno));
+ RET_ERR(db->handle, ALPM_ERR_DB_CREATE, -1);
+ }
+ return 0;
+}
+
static int local_db_validate(alpm_db_t *db)
{
struct dirent *ent = NULL;
@@ -387,12 +397,19 @@ static int local_db_validate(alpm_db_t *db)
dbdir = opendir(dbpath);
if(dbdir == NULL) {
if(errno == ENOENT) {
- /* database dir doesn't exist yet */
- db->status |= DB_STATUS_VALID;
- db->status &= ~DB_STATUS_INVALID;
- db->status &= ~DB_STATUS_EXISTS;
- db->status |= DB_STATUS_MISSING;
- return 0;
+ /* local database dir doesn't exist yet - create it */
+ if(local_db_create(db, dbpath) == 0) {
+ db->status |= DB_STATUS_VALID;
+ db->status &= ~DB_STATUS_INVALID;
+ db->status |= DB_STATUS_EXISTS;
+ db->status &= ~DB_STATUS_MISSING;
+ return 0;
+ } else {
+ db->status &= ~DB_STATUS_EXISTS;
+ db->status |= DB_STATUS_MISSING;
+ /* pm_errno is set by local_db_create */
+ return -1;
+ }
} else {
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
}
@@ -445,7 +462,9 @@ static int local_db_populate(alpm_db_t *db)
if(db->status & DB_STATUS_INVALID) {
RET_ERR(db->handle, ALPM_ERR_DB_INVALID, -1);
}
- /* note: DB_STATUS_MISSING is not fatal for local database */
+ if(db->status & DB_STATUS_MISSING) {
+ RET_ERR(db->handle, ALPM_ERR_DB_NOT_FOUND, -1);
+ }
dbpath = _alpm_db_path(db);
if(dbpath == NULL) {
@@ -455,13 +474,6 @@ static int local_db_populate(alpm_db_t *db)
dbdir = opendir(dbpath);
if(dbdir == NULL) {
- if(errno == ENOENT) {
- /* no database existing yet is not an error */
- db->status &= ~DB_STATUS_EXISTS;
- db->status |= DB_STATUS_MISSING;
- db->pkgcache = _alpm_pkghash_create(0);
- return 0;
- }
RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1);
}
if(fstat(dirfd(dbdir), &buf) != 0) {