pm

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

commit 365b4680352256efca096caabfcedb6ef654f17d
parent 74821245d8bf64da7337c48a14622371499a8e4f
Author: z3bra <willyatmailoodotorg>
Date:   Tue Jun 21 01:52:52 +0200

Specify pack loading method explicitely

Diffstat:
pm.c | 35++++++++++-------------------------
1 file changed, 10 insertions(+), 25 deletions(-)
diff --git a/pm.c b/pm.c @@ -63,7 +63,6 @@ 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); -struct pack *pack_load(const char *datadir, char *path); void pack_free(struct pack *p); int pack_extract(const char *rootfs, const char *datadir, struct pack *p); int pack_install(const char *rootfs, const char *datadir, struct pack *p); @@ -192,13 +191,17 @@ pack_load_tarball(char *path) regmatch_t sub[3]; size_t i, nmatch = 3, sublen[3]; + fn = base_name(path); + if (re_match(PACK_FORMAT, fn) != 0) { + fprintf(stderr, "%s: invalid filename\n", fn); + return NULL; + } + if (stat(path, &st) < 0) { perror(path); return NULL; } - fn = base_name(path); - regcomp(&preg, regex, 0); regexec(&preg, fn, nmatch, sub, 0); @@ -240,7 +243,7 @@ pack_load_metadata(const char *datadir, char *name) snprintf(tmp, PATH_MAX, "%s/%s", datadir, name); if (stat(tmp, &st) < 0) { - perror(tmp); + fprintf(stderr, "%s: no such pack installed\n", name); return NULL; } @@ -259,24 +262,6 @@ pack_load_metadata(const char *datadir, char *name) /* - * Guess how a pack should be loaded depending on the path given - */ -struct pack * -pack_load(const char *datadir, char *path) -{ - struct pack *p = NULL; - - if (re_match(PACK_FORMAT, path) == 0) { - p = pack_load_tarball(path); - } else { - p = pack_load_metadata(datadir, path); - } - - return p; -} - - -/* * Free a pack structure */ void @@ -745,7 +730,7 @@ install(const char *rootfs, const char *datadir, char *path) int r = 0; struct pack *p = NULL; - if ((p = pack_load(datadir, path)) == NULL) + if ((p = pack_load_tarball(path)) == NULL) return ERR_PACK_LOAD; @@ -770,7 +755,7 @@ update(const char *rootfs, const char *datadir, char *path) int r = 0, tmp = overwrite; struct pack *p = NULL; - if ((p = pack_load(datadir, path)) == NULL) + if ((p = pack_load_tarball(path)) == NULL) return ERR_PACK_LOAD; if (pack_delete(rootfs, datadir, p) != 0) @@ -798,7 +783,7 @@ delete(const char *rootfs, const char *datadir, char *name) int r = 0; struct pack *p = NULL; - if ((p = pack_load(datadir, name)) == NULL) + if ((p = pack_load_metadata(datadir, name)) == NULL) return ERR_PACK_LOAD; r += pack_delete(rootfs, datadir, p);