pm

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

commit b613d5ebdb9d76571ae6be652757ec6e3c6baf4d
parent 719fc796cedbdd1b2db385d7a6235370d2d21abc
Author: z3bra <contactatz3bradotorg>
Date:   Fri Dec 16 10:40:34 +0100

Allow disabling repository aware features

Diffstat:
config.mk | 2+-
pm.c | 102++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
2 files changed, 60 insertions(+), 44 deletions(-)
diff --git a/config.mk b/config.mk @@ -4,6 +4,6 @@ LD = ${CC} PREFIX = /usr/local MANDIR = ${PREFIX}/man -CFLAGS = -Wall -Wextra -pedantic +CFLAGS = -Wall -Wextra -pedantic -DREPOAWARE LDFLAGS = -static LIBS = -larchive -lacl -lbz2 -llzma -lz diff --git a/pm.c b/pm.c @@ -66,7 +66,9 @@ 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); +#ifdef REPOAWARE int pack_find(char *, char *); +#endif 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); @@ -280,6 +282,47 @@ pack_free(struct pack *p) } +#ifdef REPOAWARE +/* + * 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], status; + size_t len = 0; + + pipe(fd); + if (!fork()) { + close(1); + close(fd[0]); + dup2(fd[1], 1); + execlp(REPO_EXEC, REPO_EXEC, name, NULL); + } + + close(fd[1]); + + wait(&status); + if (status) + exit(1); + + len = read(fd[0], out, PATH_MAX); + close(fd[0]); + + if (len < 1) + return -1; + + out[len - 1] = 0; + + return 0; +} +#endif + + /* * Extract a tarball to the given directory */ @@ -769,10 +812,16 @@ install(const char *rootfs, const char *datadir, char *name) char path[PATH_MAX]; struct pack *p = NULL; - if (re_match(PACK_FORMAT, name) != 0) + if (re_match(PACK_FORMAT, name) != 0) { +#ifdef REPOAWARE pack_find(name, path); - else +#else + fprintf(stderr, "%s: invalid filename\n", name); + exit(1); +#endif + } else { snprintf(path, PATH_MAX, "%s", name); + } if ((p = pack_load_tarball(path)) == NULL) return ERR_PACK_LOAD; @@ -789,45 +838,6 @@ install(const char *rootfs, const char *datadir, char *name) /* - * 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], status; - size_t len = 0; - - pipe(fd); - if (!fork()) { - close(1); - close(fd[0]); - dup2(fd[1], 1); - execlp(REPO_EXEC, REPO_EXEC, name, NULL); - } - - close(fd[1]); - - wait(&status); - if (status) - exit(1); - - len = read(fd[0], out, PATH_MAX); - close(fd[0]); - - 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 */ @@ -838,10 +848,16 @@ update(const char *rootfs, const char *datadir, char *name) char path[PATH_MAX]; struct pack *p = NULL; - if (re_match(PACK_FORMAT, name) != 0) + if (re_match(PACK_FORMAT, name) != 0) { +#ifdef REPOAWARE pack_find(name, path); - else +#else + fprintf(stderr, "%s: invalid filename\n", name); + exit(1); +#endif + } else { snprintf(path, PATH_MAX, "%s", name); + } if ((p = pack_load_tarball(path)) == NULL) return ERR_PACK_LOAD;