[pacman-dev] [PATCH 2/4 v2] Add version file when creating local database directory
Allan McRae
allan at archlinux.org
Mon Sep 22 08:44:59 EDT 2014
The version of the local pacman database is stored in its root in the file
.alpm_db_version. The version is starting at 9, corresponding to the
next libalpm library version.
Signed-off-by: Allan McRae <allan at archlinux.org>
---
lib/libalpm/be_local.c | 18 ++++++++++++++++++
test/pacman/pmdb.py | 2 ++
2 files changed, 20 insertions(+)
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index d18e9ad..8d78ba5 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -44,6 +44,9 @@
#include "deps.h"
#include "filelist.h"
+/* local database format version */
+size_t ALPM_LOCAL_DB_VERSION = 9;
+
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
#define LAZY_LOAD(info, errret) \
@@ -366,6 +369,20 @@ static int is_dir(const char *path, struct dirent *entry)
return 0;
}
+static int local_db_add_version(alpm_db_t UNUSED *db, const char *dbpath)
+{
+ char dbverpath[PATH_MAX];
+ FILE *dbverfile;
+
+ snprintf(dbverpath, PATH_MAX, "%s.alpm_db_version", dbpath);
+
+ dbverfile = fopen(dbverpath, "w");
+ fprintf(dbverfile, "%zu\n", ALPM_LOCAL_DB_VERSION);
+ fclose(dbverfile);
+
+ return 0;
+}
+
static int local_db_create(alpm_db_t *db, const char *dbpath)
{
if(mkdir(dbpath, 0755) != 0) {
@@ -373,6 +390,7 @@ static int local_db_create(alpm_db_t *db, const char *dbpath)
dbpath, strerror(errno));
RET_ERR(db->handle, ALPM_ERR_DB_CREATE, -1);
}
+ local_db_add_version(db, dbpath);
return 0;
}
diff --git a/test/pacman/pmdb.py b/test/pacman/pmdb.py
index a6cf78f..a1c0239 100644
--- a/test/pacman/pmdb.py
+++ b/test/pacman/pmdb.py
@@ -87,6 +87,8 @@ def db_read(self, name):
if self.read_dircache is None:
self.read_dircache = os.listdir(self.dbdir)
for entry in self.read_dircache:
+ if entry == ".alpm_db_version":
+ continue
[pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
if pkgname == name:
dbentry = entry
--
2.1.0
More information about the pacman-dev
mailing list