URI: 
       tGive ability to fetch remote packs using an external tool - pm - barely a pack manager
  HTML git clone git://z3bra.org/pm
   DIR Log
   DIR Files
   DIR Refs
   DIR README
   DIR LICENSE
       ---
   DIR commit db07b233b50ef3e66363489c8f85cd189525a579
   DIR parent c98e93ed70eba1d6a5f7fce6b87e15179d5d3171
  HTML Author: z3bra <willyatmailoodotorg>
       Date:   Fri, 16 Dec 2016 02:07:41 +0100
       
       Give ability to fetch remote packs using an external tool
       
       Diffstat:
         M pm.c                                |      58 ++++++++++++++++++++++++++-----
       
       1 file changed, 50 insertions(+), 8 deletions(-)
       ---
   DIR diff --git a/pm.c b/pm.c
       t@@ -15,6 +15,7 @@
        
        #include "arg.h"
        
       +#define REPO_EXEC  "repo"
        #define PACK_ROOT  (getenv("ROOT")?getenv("ROOT"):"")
        #define PACK_DATA  "var/pm"
        #define PACK_BUFF_SIZE 8192
       t@@ -64,6 +65,7 @@ int re_match(const char *re, const char *str);
        struct pack *pack_load_tarball(char *path);
        struct pack *pack_load_metadata(const char *datadir, char *name);
        void pack_free(struct pack *p);
       +int  pack_find(char *, char *);
        int pack_extract(const char *rootfs, const char *datadir, struct pack *p);
        int pack_install(const char *rootfs, const char *datadir, struct pack *p);
        int pack_delete(const char *rootfs, const char *datadir, struct pack *p);
       t@@ -194,11 +196,6 @@ pack_load_tarball(char *path)
                size_t i, nmatch = 3, sublen[3];
        
                fn = base_name(path);
       -        if (re_match(PACK_FORMAT, fn) != 0) {
       -                fprintf(stderr, "%s: Invalid filename format\n", fn);
       -                return NULL;
       -        }
       -
                if (stat(path, &st) < 0) {
                        perror(path);
                        return NULL;
       t@@ -765,15 +762,20 @@ delete_metadata(const char *datadir, char *name)
         * Install a pack from the given path. This wraps load/install of a pack
         */
        int
       -install(const char *rootfs, const char *datadir, char *path)
       +install(const char *rootfs, const char *datadir, char *name)
        {
                int r = 0;
       +        char path[PATH_MAX];
                struct pack *p = NULL;
        
       +        if (re_match(PACK_FORMAT, name) != 0)
       +                pack_find(name, path);
       +        else
       +                snprintf(path, PATH_MAX, "%s", name);
       +
                if ((p = pack_load_tarball(path)) == NULL)
                        return ERR_PACK_LOAD;
        
       -
                r += pack_install(rootfs, datadir, p);
        
                if (r == 0)
       t@@ -786,15 +788,55 @@ install(const char *rootfs, const char *datadir, char *path)
        
        
        /*
       + * Find a pack filename using an external tool writing the path to the
       + * pack to stdout.
       + * The tool should be called as:
       + *
       + *        tool <name>
       + */
       +int
       +pack_find(char *name, char *out)
       +{
       +        int fd[2];
       +        size_t len = 0;
       +
       +        pipe(fd);
       +        if (!fork()) {
       +                close(1);
       +                close(fd[0]);
       +                dup2(fd[1], 1);
       +                execlp(REPO_EXEC, REPO_EXEC, name, NULL);
       +        }
       +
       +        len = read(fd[0], out, PATH_MAX);
       +        close(fd[0]);
       +        close(fd[1]);
       +
       +        if (len < 1)
       +                return -1;
       +
       +        out[len - 1] = 0;
       +
       +        return 0;
       +}
       +
       +
       +/*
         * Update a pack. This should be as easy as delete/install.
         * Deletion is required in case the file structure changes
         */
        int
       -update(const char *rootfs, const char *datadir, char *path)
       +update(const char *rootfs, const char *datadir, char *name)
        {
                int r = 0, tmp = overwrite;
       +        char path[PATH_MAX];
                struct pack *p = NULL;
        
       +        if (re_match(PACK_FORMAT, name) != 0)
       +                pack_find(name, path);
       +        else
       +                snprintf(path, PATH_MAX, "%s", name);
       +
                if ((p = pack_load_tarball(path)) == NULL)
                        return ERR_PACK_LOAD;