pm

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

commit e7c528b75ba86304b270abc8181868ed3f5efd32
parent b4f5118c0b65eea1050fbce7eee1fda92749a1e2
Author: z3bra <willyatmailoodotorg>
Date:   Mon Jan 11 23:16:21 2016

Add verbosity to delete errors

Diffstat:
 pm.c | 27 +++++++++++++++++----------
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/pm.c b/pm.c @@ -62,13 +62,12 @@ int install(char *rootfs, char *datadir, struct pack *p, int overwrite); int delete_content(FILE *metafile); int delete(const char *rootfs, const char *datadir, const char *name); - char *argv0; void usage(char *name) { - fprintf(stderr, "usage: %s -adi <pack>\n" , name); + fprintf(stderr, "usage: %s -adfi <pack>\n" , name); } @@ -86,11 +85,12 @@ is_empty(char *path) return -1; } - while ((p = readdir(d))) - if (!strcmp(p->d_name, ".") && !strcmp(p->d_name, "..")) { + while ((p = readdir(d))) { + if (strcmp(p->d_name, ".") && strcmp(p->d_name, "..")) { closedir(d); return -1; } + } closedir(d); return 0; @@ -381,14 +381,14 @@ install(char *rootfs, char *datadir, struct pack *p, int overwrite) int delete_content(FILE *f) { + int r = 0; char file[PATH_MAX] = ""; struct stat st; size_t len = 0; if (fgets(file, PATH_MAX, f)) - if (delete_content(f) < 0) { - return -1; - } + if ((r = delete_content(f)) < 0) + return r; /* remove trailing '\n' */ if ((len = strnlen(file, PATH_MAX)) == 0) @@ -411,10 +411,15 @@ delete_content(FILE *f) return 0; if (S_ISDIR(st.st_mode) && is_empty(file) == 0) { - return rmdir(file); + if ((r = rmdir(file)) < 0) + perror(file); + return r; } - return unlink(file); + if (!S_ISDIR(st.st_mode) && (r = unlink(file)) < 0) + perror(file); + + return r; } @@ -442,7 +447,7 @@ delete(const char *rootfs, const char *datadir, const char *packname) /* ignore errors so everything gets deleted */ if (delete_content(f) < 0) { - fprintf(stderr, "%s: Could not remove pack\n", packname); + fprintf(stderr, "%s: Cannot remove pack\n", packname); fclose(f); return ERR_DELETE; } @@ -450,12 +455,14 @@ delete(const char *rootfs, const char *datadir, const char *packname) if (unlink(meta) < 0) { perror(meta); + fprintf(stderr, "%s: Cannot remove metadata\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); return ERR_DELETE; }