pkgtools

morpheus pkg tools
git clone git://git.2f30.org/pkgtools
Log | Files | Refs | README | LICENSE

commit 19d5d7b4eccdd59a0a66ce94c62a1d474fc9b7eb
parent e54beb9f486a1329de54469aa8591235c3b53866
Author: sin <sin@2f30.org>
Date:   Fri, 20 Jun 2014 16:11:09 +0100

db_rm() should work on a struct pkg

Diffstat:
Mdb.c | 42+++++++++++++++++++-----------------------
Mdb.h | 2+-
Mremovepkg.c | 7+++----
3 files changed, 23 insertions(+), 28 deletions(-)

diff --git a/db.c b/db.c @@ -187,33 +187,29 @@ db_add(struct db *db, const char *file) return 0; } -/* Physically unlink the db entry for `file' */ +/* Physically unlink the db entry for `pkg' */ int -db_rm(struct db *db, const char *name) +db_rm(struct db *db, struct pkg *pkg) { - struct pkg *pkg; char path[PATH_MAX]; - for (pkg = db->head; pkg; pkg = pkg->next) { - if (pkg->deleted == 1 && strcmp(pkg->name, name) == 0) { - estrlcpy(path, db->path, sizeof(path)); - estrlcat(path, "/", sizeof(path)); - estrlcat(path, pkg->name, sizeof(path)); - if (pkg->version) { - estrlcat(path, "#", sizeof(path)); - estrlcat(path, pkg->version, - sizeof(path)); - } - if (vflag == 1) - printf("removing %s\n", path); - if (remove(path) < 0) { - weprintf("remove %s:", path); - return -1; - } - sync(); - break; - } + if (pkg->deleted == 0) + return -1; + estrlcpy(path, db->path, sizeof(path)); + estrlcat(path, "/", sizeof(path)); + estrlcat(path, pkg->name, sizeof(path)); + if (pkg->version) { + estrlcat(path, "#", sizeof(path)); + estrlcat(path, pkg->version, + sizeof(path)); + } + if (vflag == 1) + printf("removing %s\n", path); + if (remove(path) < 0) { + weprintf("remove %s:", path); + return -1; } + sync(); return 0; } @@ -484,7 +480,7 @@ rm_empty_dir(const char *f, const struct stat *sb, int typeflag, return 0; } -/* Remove the package entries for `file' */ +/* Remove the package entries for `pkg' */ int pkg_remove(struct db *db, struct pkg *pkg) { diff --git a/db.h b/db.h @@ -30,7 +30,7 @@ extern int vflag; struct db *db_new(const char *); int db_free(struct db *); int db_add(struct db *, const char *); -int db_rm(struct db *, const char *); +int db_rm(struct db *, struct pkg *); int db_load(struct db *); int db_walk(struct db *, int (*)(struct db *, struct pkg *, void *), void *); int db_links(struct db *, const char *); diff --git a/removepkg.c b/removepkg.c @@ -57,10 +57,7 @@ main(int argc, char *argv[]) if (r < 0) { db_free(db); exit(EXIT_FAILURE); - } else if (r > 0) { - db_rm(db, argv[i]); - printf("removed %s\n", argv[i]); - } else { + } else if (r == 0) { printf("%s is not installed\n", argv[i]); } } @@ -76,6 +73,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(db, pkg); + printf("removed %s\n", pkg->name); return 1; } return 0;