[pacman-dev] [PATCH 3/5] Add version file to empty local database
Allan McRae
allan at archlinux.org
Tue Jul 16 08:22:42 EDT 2013
If a user manually creates the local database directory, or has an empty
local database for some other reason, we silently add a version file
Signed-off-by: Allan McRae <allan at archlinux.org>
---
lib/libalpm/be_local.c | 50 +++++++++++++++++++++++++-------------------------
test/pacman/pmtest.py | 3 +++
2 files changed, 28 insertions(+), 25 deletions(-)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index eb462df..fe9e05a 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;
@@ -435,37 +436,36 @@ static int local_db_validate(alpm_db_t *db)
db->status |= DB_STATUS_EXISTS;
db->status &= ~DB_STATUS_MISSING;
- while((ent = readdir(dbdir)) != NULL) {
- const char *name = ent->d_name;
- char path[PATH_MAX];
+ snprintf(dbverpath, PATH_MAX, "%s.alpm_db_version", dbpath);
- if(strcmp(name, ".") == 0 || strcmp(name, "..") == 0) {
- continue;
- }
- if(!is_dir(dbpath, ent)) {
- continue;
+ 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 {
+ closedir(dbdir);
+ goto version_error;
+ }
}
- 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;
- }
- }
- /* we found no depends file after full scan */
- db->status |= DB_STATUS_VALID;
- db->status &= ~DB_STATUS_INVALID;
- ret = 0;
+ local_db_add_version(db, dbpath);
-done:
- if(dbdir) {
closedir(dbdir);
+ goto version_latest;
}
- return ret;
+version_latest:
+ db->status |= DB_STATUS_VALID;
+ db->status &= ~DB_STATUS_INVALID;
+ return 0;
+
+version_error:
+ 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)
diff --git a/test/pacman/pmtest.py b/test/pacman/pmtest.py
index f5a9680..307a752 100644
--- a/test/pacman/pmtest.py
+++ b/test/pacman/pmtest.py
@@ -180,6 +180,9 @@ def generate(self, pacman):
for pkg in self.db["local"].pkgs:
vprint("\tinstalling %s" % pkg.fullname())
pkg.install_package(self.root)
+ if self.db["local"].pkgs:
+ path = os.path.join(self.root, util.PM_DBPATH, "local")
+ util.mkfile(path, ".alpm_db_version", "9")
# Done.
vprint(" Taking a snapshot of the file system")
--
1.8.3.3
More information about the pacman-dev
mailing list