Add version file when creating local database directory
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@archlinux.org>
This commit is contained in:
parent
d3f5ab0e70
commit
7e9ad22ac2
2 changed files with 20 additions and 0 deletions
|
@ -44,6 +44,9 @@
|
||||||
#include "deps.h"
|
#include "deps.h"
|
||||||
#include "filelist.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);
|
static int local_db_read(alpm_pkg_t *info, alpm_dbinfrq_t inforeq);
|
||||||
|
|
||||||
#define LAZY_LOAD(info, errret) \
|
#define LAZY_LOAD(info, errret) \
|
||||||
|
@ -366,6 +369,20 @@ static int is_dir(const char *path, struct dirent *entry)
|
||||||
return 0;
|
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, "%sALPM_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)
|
static int local_db_create(alpm_db_t *db, const char *dbpath)
|
||||||
{
|
{
|
||||||
if(mkdir(dbpath, 0755) != 0) {
|
if(mkdir(dbpath, 0755) != 0) {
|
||||||
|
@ -373,6 +390,7 @@ static int local_db_create(alpm_db_t *db, const char *dbpath)
|
||||||
dbpath, strerror(errno));
|
dbpath, strerror(errno));
|
||||||
RET_ERR(db->handle, ALPM_ERR_DB_CREATE, -1);
|
RET_ERR(db->handle, ALPM_ERR_DB_CREATE, -1);
|
||||||
}
|
}
|
||||||
|
local_db_add_version(db, dbpath);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -87,6 +87,8 @@ class pmdb(object):
|
||||||
if self.read_dircache is None:
|
if self.read_dircache is None:
|
||||||
self.read_dircache = os.listdir(self.dbdir)
|
self.read_dircache = os.listdir(self.dbdir)
|
||||||
for entry in self.read_dircache:
|
for entry in self.read_dircache:
|
||||||
|
if entry == "ALPM_DB_VERSION":
|
||||||
|
continue
|
||||||
[pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
|
[pkgname, pkgver, pkgrel] = entry.rsplit("-", 2)
|
||||||
if pkgname == name:
|
if pkgname == name:
|
||||||
dbentry = entry
|
dbentry = entry
|
||||||
|
|
Loading…
Add table
Reference in a new issue