commit 293d15ae8d10390be1749761d08d72636c926015
parent ac1c86f65589a9d82e5f2e72c27a039bb2dde606
Author: sin <sin@2f30.org>
Date: Tue, 24 Jun 2014 15:32:30 +0100
Move deleted packages to a separate list
Diffstat:
3 files changed, 26 insertions(+), 11 deletions(-)
diff --git a/db.c b/db.c
@@ -13,6 +13,7 @@ db_new(const char *prefix)
db = emalloc(sizeof(*db));
TAILQ_INIT(&db->pkg_head);
+ TAILQ_INIT(&db->pkg_rm_head);
if (!realpath(prefix, db->prefix)) {
weprintf("realpath %s:", prefix);
@@ -53,6 +54,12 @@ db_free(struct db *db)
tmp = TAILQ_NEXT(pkg, entry);
pkg_free(pkg);
}
+
+ for (pkg = TAILQ_FIRST(&db->pkg_rm_head); pkg; pkg = tmp) {
+ tmp = TAILQ_NEXT(pkg, entry);
+ pkg_free(pkg);
+ }
+
closedir(db->pkgdir);
rej_free(db);
free(db);
@@ -104,16 +111,23 @@ db_add(struct db *db, struct pkg *pkg)
/* Physically unlink the db entry for the given package */
int
-db_rm(struct pkg *pkg)
+db_rm(struct db *db, struct pkg *pkg)
{
- if (vflag == 1)
- printf("removing %s\n", pkg->path);
- if (remove(pkg->path) < 0) {
- weprintf("remove %s:", pkg->path);
- return -1;
+ struct pkg *tmp;
+
+ TAILQ_FOREACH(tmp, &db->pkg_rm_head, entry) {
+ if (strcmp(tmp->name, pkg->name) == 0) {
+ if (vflag == 1)
+ printf("removing %s\n", pkg->path);
+ if (remove(pkg->path) < 0) {
+ weprintf("remove %s:", pkg->path);
+ return -1;
+ }
+ sync();
+ return 0;
+ }
}
- sync();
- return 0;
+ return -1;
}
/* Load all packages in the db */
@@ -430,6 +444,7 @@ pkg_remove(struct db *db, struct pkg *pkg)
}
TAILQ_REMOVE(&db->pkg_head, pkg, entry);
+ TAILQ_INSERT_TAIL(&db->pkg_rm_head, pkg, entry);
return 0;
}
diff --git a/pkg.h b/pkg.h
@@ -47,6 +47,7 @@ struct db {
char path[PATH_MAX]; /* absolute path to DBPATH including db prefix */
TAILQ_HEAD(rejrule_head, rejrule) rejrule_head;
TAILQ_HEAD(pkg_head, pkg) pkg_head;
+ TAILQ_HEAD(pkg_rm_head, pkg) pkg_rm_head;
};
/* db.c */
@@ -60,7 +61,7 @@ extern char *argv0;
struct db *db_new(const char *);
int db_free(struct db *);
int db_add(struct db *, struct pkg *);
-int db_rm(struct pkg *);
+int db_rm(struct db *, struct pkg *);
int db_load(struct db *);
struct pkg *pkg_load_file(struct db *, const char *);
int db_walk(struct db *, int (*)(struct db *, struct pkg *, void *), void *);
diff --git a/removepkg.c b/removepkg.c
@@ -68,9 +68,8 @@ pkg_remove_cb(struct db *db, struct pkg *pkg, void *name)
if (strcmp(pkg->name, name) == 0) {
if (pkg_remove(db, pkg) < 0)
return -1;
- db_rm(pkg);
+ db_rm(db, pkg);
printf("removed %s\n", pkg->name);
- pkg_free(pkg);
return 1;
}
return 0;