[pacman-dev] [PATCH 4/4 v2] Check the version of the local database during validation
Allan McRae
allan at archlinux.org
Mon Sep 22 08:45:01 EDT 2014
When we check the database version directly, there is no longer a
need to scan for depends files.
Signed-off-by: Allan McRae <allan at archlinux.org>
---
It is much easier to look at the before and after here instead of the patch directly.
lib/libalpm/be_local.c | 25 ++++++++-----------------
1 file changed, 8 insertions(+), 17 deletions(-)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index 1707a76..2b7260e 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -398,9 +398,11 @@ static int local_db_validate(alpm_db_t *db)
{
struct dirent *ent = NULL;
const char *dbpath;
+ DIR *dbdir;
char dbverpath[PATH_MAX];
FILE *dbverfile;
- DIR *dbdir;
+ int t;
+ size_t version;
if(db->status & DB_STATUS_VALID) {
return 0;
@@ -453,26 +455,15 @@ static int local_db_validate(alpm_db_t *db)
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];
+ t = fscanf(dbverfile, "%zu", &version);
+ (void)t;
- if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
- continue;
- }
- if(!is_dir(dbpath, ent)) {
- continue;
- }
+ fclose(dbverfile);
- snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name);
- if(access(path, F_OK) == 0) {
- /* we found a depends file- bail */
- goto version_error;
- }
+ if(version != ALPM_LOCAL_DB_VERSION) {
+ goto version_error;
}
- /* we found no depends file after full scan */
version_latest:
closedir(dbdir);
--
2.1.0
More information about the pacman-dev
mailing list