pm

barely a pack manager
git clone git://z3bra.org/pm
Log | Files | Refs | README | LICENSE

commit 73f293913081b16d19635ceb544530a6d7915d48
parent f4ccf788a420f7764b4ecfc6288a0622e6777e33
Author: z3bra <willyatmailoodotorg>
Date:   Tue Jan 12 14:39:48 2016

Check for installed packs before deletion

Diffstat:
 pm.c | 33 ++++++++++++++++++++-------------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/pm.c b/pm.c @@ -476,11 +476,18 @@ int delete(const char *rootfs, const char *datadir, const char *packname) { FILE *f; - char meta[PATH_MAX]; + char tmp[PATH_MAX]; + struct stat st; + + snprintf(tmp, PATH_MAX, "%s/%s", datadir, packname); + if (stat(tmp, &st) < 0 && errno == ENOENT) { + fprintf(stderr, "%s: not installed\n", packname); + return -1; + } - snprintf(meta, PATH_MAX, "%s/%s/files", datadir, packname); - if ((f = fopen(meta, "r")) == NULL) { - perror(meta); + snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, packname); + if ((f = fopen(tmp, "r")) == NULL) { + perror(tmp); return ERR_DELETE; } @@ -497,21 +504,21 @@ delete(const char *rootfs, const char *datadir, const char *packname) } fclose(f); - if (unlink(meta) < 0) { - perror(meta); - fprintf(stderr, "%s: cannot remove metadata\n", packname); + if (unlink(tmp) < 0) { + perror(tmp); + fprintf(stderr, "%s: cannot remove file list\n", packname); return ERR_DELETE; } - snprintf(meta, PATH_MAX, "%s/%s/version", datadir, packname); - if (unlink(meta) < 0) { - perror(meta); - fprintf(stderr, "%s: cannot clean metadata\n", packname); + snprintf(tmp, PATH_MAX, "%s/%s/version", datadir, packname); + if (unlink(tmp) < 0) { + perror(tmp); + fprintf(stderr, "%s: cannot clean version\n", packname); return ERR_DELETE; } - snprintf(meta, PATH_MAX, "%s/%s", datadir, packname); - return rmdir(meta); + snprintf(tmp, PATH_MAX, "%s/%s", datadir, packname); + return rmdir(tmp); }