pkgtools

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

commit a20ad556bb022ee29a5eb4b30382c993fbbfb8b0
parent e5492f5e26d6520f426ba3978410dc70cc3f88c9
Author: sin <sin@2f30.org>
Date:   Tue, 17 Jun 2014 14:46:12 +0100

Remove dbfind() and error out when removing a package that is not installed

Some more stylistic fixes.

Diffstat:
Mdb.c | 35+++++++++++------------------------
Mremovepkg.c | 14++++++++++----
2 files changed, 21 insertions(+), 28 deletions(-)

diff --git a/db.c b/db.c @@ -92,21 +92,8 @@ dbload(struct db *db) return 0; } -struct pkg * -dbfind(struct db *db, const char *name) -{ - struct dbentry *de; - - for (de = db->head; de; de = de->next) - if (de->deleted == 0 && strcmp(de->pkg->name, name) == 0) - break; - if (!de) - return NULL; - return de->pkg; -} - int -dbfscollide(struct db *db, const char *name) +dbfscollide(struct db *db, const char *file) { char pkgpath[PATH_MAX]; char path[PATH_MAX]; @@ -116,7 +103,7 @@ dbfscollide(struct db *db, const char *name) int ok = 0; int r; - realpath(name, pkgpath); + realpath(file, pkgpath); ar = archive_read_new(); @@ -159,7 +146,7 @@ dbfscollide(struct db *db, const char *name) } int -dbadd(struct db *db, const char *name) +dbadd(struct db *db, const char *file) { char pkgpath[PATH_MAX], tmppath[PATH_MAX]; char path[PATH_MAX]; @@ -168,7 +155,7 @@ dbadd(struct db *db, const char *name) struct archive_entry *entry; int r; - realpath(name, pkgpath); + realpath(file, pkgpath); estrlcpy(tmppath, pkgpath, sizeof(tmppath)); estrlcpy(path, db->path, sizeof(path)); @@ -341,7 +328,7 @@ dbpkgload(struct db *db, struct pkg *pkg) } int -dbpkginstall(struct db *db, const char *name) +dbpkginstall(struct db *db, const char *file) { char cwd[PATH_MAX]; char pkgpath[PATH_MAX]; @@ -350,7 +337,7 @@ dbpkginstall(struct db *db, const char *name) int flags; int r; - realpath(name, pkgpath); + realpath(file, pkgpath); ar = archive_read_new(); @@ -418,7 +405,7 @@ rmemptydir(const char *f, const struct stat *sb, int typeflag, } int -dbpkgremove(struct db *db, const char *name) +dbpkgremove(struct db *db, const char *file) { struct dbentry *de; struct pkg *pkg; @@ -426,7 +413,7 @@ dbpkgremove(struct db *db, const char *name) struct stat sb; char tmppath[PATH_MAX], *p; - estrlcpy(tmppath, name, sizeof(tmppath)); + estrlcpy(tmppath, file, sizeof(tmppath)); p = basename(tmppath); for (de = db->head; de; de = de->next) { @@ -438,7 +425,7 @@ dbpkgremove(struct db *db, const char *name) } } if (!de) { - weprintf("%s: is not installed\n", name); + weprintf("can't find %s in pkg db\n", p); return -1; } @@ -484,12 +471,12 @@ dbpkgremove(struct db *db, const char *name) } int -dbrm(struct db *db, const char *name) +dbrm(struct db *db, const char *file) { struct dbentry *de; char path[PATH_MAX], tmpname[PATH_MAX], *p; - estrlcpy(tmpname, name, sizeof(tmpname)); + estrlcpy(tmpname, file, sizeof(tmpname)); p = basename(tmpname); for (de = db->head; de; de = de->next) { if (de->deleted == 1 && strcmp(de->pkg->name, p) == 0) { diff --git a/removepkg.c b/removepkg.c @@ -54,10 +54,14 @@ main(int argc, char *argv[]) for (i = 0; i < argc; i++) { realpath(argv[i], path); r = dbwalk(db, removepkg, path); - if (r < 0) + if (r < 0) { exit(EXIT_FAILURE); - dbrm(db, path); - printf("removed %s\n", path); + } else if (r > 0) { + dbrm(db, path); + printf("removed %s\n", path); + } else { + printf("%s is not installed\n", path); + } } dbfree(db); @@ -72,8 +76,10 @@ removepkg(struct db *db, struct pkg *pkg, void *file) estrlcpy(name, file, sizeof(name)); p = basename(name); - if (strcmp(pkg->name, p) == 0) + if (strcmp(pkg->name, p) == 0) { if (dbpkgremove(db, p) < 0) return -1; + return 1; + } return 0; }