1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Check the version of the local database during validation

When we check the database version directly, there is no longer a
need to scan for depends files.

Signed-off-by: Allan McRae <allan@archlinux.org>
This commit is contained in:
Allan McRae 2013-07-16 21:51:16 +10:00
parent 1660ed3cf9
commit d02efd2f20
2 changed files with 13 additions and 20 deletions

View File

@ -398,9 +398,11 @@ static int local_db_validate(alpm_db_t *db)
{ {
struct dirent *ent = NULL; struct dirent *ent = NULL;
const char *dbpath; const char *dbpath;
DIR *dbdir;
char dbverpath[PATH_MAX]; char dbverpath[PATH_MAX];
FILE *dbverfile; FILE *dbverfile;
DIR *dbdir; int t;
size_t version;
if(db->status & DB_STATUS_VALID) { if(db->status & DB_STATUS_VALID) {
return 0; return 0;
@ -437,7 +439,7 @@ static int local_db_validate(alpm_db_t *db)
db->status |= DB_STATUS_EXISTS; db->status |= DB_STATUS_EXISTS;
db->status &= ~DB_STATUS_MISSING; db->status &= ~DB_STATUS_MISSING;
snprintf(dbverpath, PATH_MAX, "%s.alpm_db_version", dbpath); snprintf(dbverpath, PATH_MAX, "%sALPM_DB_VERSION", dbpath);
if((dbverfile = fopen(dbverpath, "r")) == NULL) { if((dbverfile = fopen(dbverpath, "r")) == NULL) {
/* create dbverfile if local database is empty - otherwise version error */ /* create dbverfile if local database is empty - otherwise version error */
@ -453,26 +455,17 @@ static int local_db_validate(alpm_db_t *db)
local_db_add_version(db, dbpath); local_db_add_version(db, dbpath);
goto version_latest; goto version_latest;
} }
t = fscanf(dbverfile, "%zu", &version);
fclose(dbverfile); fclose(dbverfile);
while((ent = readdir(dbdir)) != NULL) { if(t != 1) {
const char *name = ent->d_name;
char path[PATH_MAX];
if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
continue;
}
if(!is_dir(dbpath, ent)) {
continue;
}
snprintf(path, PATH_MAX, "%s%s/depends", dbpath, name);
if(access(path, F_OK) == 0) {
/* we found a depends file- bail */
goto version_error; goto version_error;
} }
if(version != ALPM_LOCAL_DB_VERSION) {
goto version_error;
} }
/* we found no depends file after full scan */
version_latest: version_latest:
closedir(dbdir); closedir(dbdir);

View File

@ -182,7 +182,7 @@ class pmtest(object):
pkg.install_package(self.root) pkg.install_package(self.root)
if self.db["local"].pkgs: if self.db["local"].pkgs:
path = os.path.join(self.root, util.PM_DBPATH, "local") path = os.path.join(self.root, util.PM_DBPATH, "local")
util.mkfile(path, ".alpm_db_version", "9") util.mkfile(path, "ALPM_DB_VERSION", "9")
# Done. # Done.
vprint(" Taking a snapshot of the file system") vprint(" Taking a snapshot of the file system")