index : pacman | |
Archlinux32 fork of pacman | gitolite user |
summaryrefslogtreecommitdiff |
author | Allan McRae <allan@archlinux.org> | 2013-07-16 21:48:38 +1000 |
---|---|---|
committer | Allan McRae <allan@archlinux.org> | 2014-09-23 21:27:11 +1000 |
commit | 1660ed3cf9069f84d96670b5443a9f1542b7865d (patch) | |
tree | dcead4ae0bc06c4c2ea2a15d0aedf793f79071b6 /lib | |
parent | 7e9ad22ac21329adcf470bb00f2d0a386376fddf (diff) |
-rw-r--r-- | lib/libalpm/be_local.c | 44 |
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c index 7df0ff88..857c984f 100644 --- a/lib/libalpm/be_local.c +++ b/lib/libalpm/be_local.c @@ -398,8 +398,9 @@ static int local_db_validate(alpm_db_t *db) { struct dirent *ent = NULL; const char *dbpath; + char dbverpath[PATH_MAX]; + FILE *dbverfile; DIR *dbdir; - int ret = -1; if(db->status & DB_STATUS_VALID) { return 0; @@ -412,6 +413,7 @@ static int local_db_validate(alpm_db_t *db) if(dbpath == NULL) { RET_ERR(db->handle, ALPM_ERR_DB_OPEN, -1); } + dbdir = opendir(dbpath); if(dbdir == NULL) { if(errno == ENOENT) { @@ -435,6 +437,24 @@ static int local_db_validate(alpm_db_t *db) db->status |= DB_STATUS_EXISTS; db->status &= ~DB_STATUS_MISSING; + snprintf(dbverpath, PATH_MAX, "%s.alpm_db_version", dbpath); + + if((dbverfile = fopen(dbverpath, "r")) == NULL) { + /* create dbverfile if local database is empty - otherwise version error */ + while((ent = readdir(dbdir)) != NULL) { + const char *name = ent->d_name; + if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) { + continue; + } else { + goto version_error; + } + } + + local_db_add_version(db, dbpath); + goto version_latest; + } + fclose(dbverfile); + while((ent = readdir(dbdir)) != NULL) { const char *name = ent->d_name; char path[PATH_MAX]; @@ -449,23 +469,23 @@ static int local_db_validate(alpm_db_t *db) snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name); if(access(path, F_OK) == 0) { /* we found a depends file- bail */ - db->status &= ~DB_STATUS_VALID; - db->status |= DB_STATUS_INVALID; - db->handle->pm_errno = ALPM_ERR_DB_VERSION; - goto done; + goto version_error; } } /* we found no depends file after full scan */ + +version_latest: + closedir(dbdir); db->status |= DB_STATUS_VALID; db->status &= ~DB_STATUS_INVALID; - ret = 0; - -done: - if(dbdir) { - closedir(dbdir); - } + return 0; - return ret; +version_error: + closedir(dbdir); + db->status &= ~DB_STATUS_VALID; + db->status |= DB_STATUS_INVALID; + db->handle->pm_errno = ALPM_ERR_DB_VERSION; + return -1; } static int local_db_populate(alpm_db_t *db) |