URI: 
       tPass datadir as an argument to pack_delete() - pm - barely a pack manager
  HTML git clone git://z3bra.org/pm
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit 5f251565fd50d808e101a1dcbce3ed48fb9502bb
   DIR parent 9d2a5bb11a9e4ca685764375ff8dd6e0f4062b9a
  HTML Author: z3bra <willyatmailoodotorg>
       Date:   Sat, 18 Jun 2016 01:17:35 +0200
       
       Pass datadir as an argument to pack_delete()
       
       Diffstat:
         M pm.c                                |      22 +++++++++++++---------
       
       1 file changed, 13 insertions(+), 9 deletions(-)
       ---
   DIR diff --git a/pm.c b/pm.c
       t@@ -56,8 +56,7 @@ struct pack *pack_load_directory(const char *datadir, char *path);
        struct pack *pack_load(const char *datadir, char *path);
        void pack_free(struct pack *p);
        int pack_install(const char *rootfs, const char *datadir, struct pack *p);
       -int pack_delete(const char *rootfs, struct pack *p);
       -
       +int pack_delete(const char *rootfs, const char *datadir, struct pack *p);
        
        int inspect_collision(const char *rootfs, struct pack *p);
        int inspect_system(int fd, const char *datadir);
       t@@ -147,6 +146,7 @@ base_name(char *path)
                return b ? b + 1 : path;
        }
        
       +
        int
        inspect_version(const char *datadir, const char *name, char version[LINE_MAX])
        {
       t@@ -154,7 +154,6 @@ inspect_version(const char *datadir, const char *name, char version[LINE_MAX])
                char tmp[PATH_MAX] = "", *lf = NULL;
        
                snprintf(tmp, PATH_MAX, "%s/%s/version", datadir, name);
       -
                if ((stream = fopen(tmp, "r")) == NULL) {
                        sprintf(version, "(unknown)");
                        return 1;
       t@@ -170,6 +169,7 @@ inspect_version(const char *datadir, const char *name, char version[LINE_MAX])
                return 0;
        }
        
       +
        /*
         * Check for collisions between the filesystem and the tarball
         */
       t@@ -515,10 +515,15 @@ delete_content(char *map, size_t size)
                         * beginning of the file. If it's an \n, we replace it by 0 and
                         * process to the deletion of the inode, either with rmdir or
                         * unlink.
       +                 *
       +                 * When setting the path, the current offset is either at the
       +                 * start of the file, or on a 0 (freshly replaced \n). In case
       +                 * We are on a 0, the path should be set to the string just
       +                 * after (&map[off] + 1). This doesn't apply to start of file.
                         */
                        for (off=size-1; off>0 && map[off] != '\n'; off--);
                        map[off] = (off > 0 ? 0 : *map);
       -                path     = (off < size-1 ? &map[off] + 1 : NULL);
       +                path     = (off < size-1 ? &map[off] + (off>0?1:0) : NULL);
        
                        if (path != NULL && strnlen(path, PATH_MAX) > 0) {
                                if (delete_node(path) < 0)
       t@@ -536,14 +541,14 @@ delete_content(char *map, size_t size)
         * and call delete_content()
         */
        int
       -pack_delete(const char *rootfs, struct pack *p)
       +pack_delete(const char *rootfs, const char *datadir, struct pack *p)
        {
                int fd;
                char *addr = NULL;
                char tmp[PATH_MAX];
                struct stat st;
        
       -        snprintf(tmp, PATH_MAX, "%s/files", p->path);
       +        snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, p->name);
                if (stat(tmp, &st) < 0 && errno == ENOENT) {
                        fprintf(stderr, "%s: not installed\n", p->name);
                        return -1;
       t@@ -625,7 +630,7 @@ update(const char *rootfs, const char *datadir, char *path)
                if ((p = pack_load(datadir, path)) == NULL)
                        return ERR_PACK_LOAD;
        
       -        if (delete(rootfs, datadir, p->name) != 0)
       +        if (pack_delete(rootfs, datadir, p) != 0)
                        return ERR_DELETE;
        
                r += pack_install(rootfs, datadir, p);
       t@@ -642,12 +647,11 @@ delete(const char *rootfs, const char *datadir, char *name)
                struct pack *p = NULL;
                char tmp[PATH_MAX] = "";
        
       -
                snprintf(tmp, PATH_MAX, "%s/%s", datadir, name);
                if ((p = pack_load(datadir, tmp)) == NULL)
                        return ERR_PACK_LOAD;
        
       -        r += pack_delete(rootfs, p);
       +        r += pack_delete(rootfs, datadir, p);
                pack_free(p);
        
                return r;