tAdd verbosity to delete errors - pm - barely a pack manager
 (HTM) git clone git://z3bra.org/pm
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e7c528b75ba86304b270abc8181868ed3f5efd32
 (DIR) parent b4f5118c0b65eea1050fbce7eee1fda92749a1e2
 (HTM) Author: z3bra <willyatmailoodotorg>
       Date:   Mon, 11 Jan 2016 23:16:21 +0100
       
       Add verbosity to delete errors
       
       Diffstat:
         M pm.c                                |      27 +++++++++++++++++----------
       
       1 file changed, 17 insertions(+), 10 deletions(-)
       ---
 (DIR) diff --git a/pm.c b/pm.c
       t@@ -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);
        }
        
        
       t@@ -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;
       t@@ -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)
       t@@ -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;
        }
        
        
       t@@ -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;
                }
       t@@ -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;
                }