Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/be_local.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-02-28 10:46:00 -0600
committerDan McGee <dan@archlinux.org>2011-02-28 10:46:00 -0600
commitf45369800abdeb54847d9ea6a326eb613f30cd3b (patch)
tree41ed4f7ae8c9fa18ed60a5b5ca1ccf6d4540bc62 /lib/libalpm/be_local.c
parent5ea4706f57e15de23a5fd36eff3bc4619aeac224 (diff)
Check local DB version before continuing transaction
Ensure we have a local DB version that is up to par with what we expect before we go down any road that might modify it. This should prevent stupid mistakes with the 3.5.X upgrade and people not running pacman-db-upgrade after the transaction as they will need to. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/be_local.c')
-rw-r--r--lib/libalpm/be_local.c53
1 files changed, 53 insertions, 0 deletions
diff --git a/lib/libalpm/be_local.c b/lib/libalpm/be_local.c
index c1e86a63..848ecc58 100644
--- a/lib/libalpm/be_local.c
+++ b/lib/libalpm/be_local.c
@@ -924,9 +924,62 @@ int _alpm_local_db_remove(pmdb_t *db, pmpkg_t *info)
return(ret);
}
+static int local_db_version(pmdb_t *db)
+{
+ struct dirent *ent = NULL;
+ const char *dbpath;
+ DIR *dbdir;
+ int version;
+
+ dbpath = _alpm_db_path(db);
+ if(dbpath == NULL) {
+ RET_ERR(PM_ERR_DB_OPEN, -1);
+ }
+ dbdir = opendir(dbpath);
+ if(dbdir == NULL) {
+ if(errno == ENOENT) {
+ /* database dir doesn't exist yet */
+ version = 2;
+ goto done;
+ } else {
+ RET_ERR(PM_ERR_DB_OPEN, -1);
+ }
+ }
+
+ while((ent = readdir(dbdir)) != NULL) {
+ 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 */
+ version = 1;
+ goto done;
+ }
+ }
+ /* we found no depends file after full scan */
+ version = 2;
+
+done:
+ if(dbdir) {
+ closedir(dbdir);
+ }
+
+ _alpm_log(PM_LOG_DEBUG, "local database version %d\n", version);
+ return(version);
+}
+
struct db_operations local_db_ops = {
.populate = local_db_populate,
.unregister = _alpm_db_unregister,
+ .version = local_db_version,
};
pmdb_t *_alpm_db_register_local(void)