pm

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

commit 2c89cf4793591b24f6ec0770250b931479972686
parent cf0441277b56ecaae38641dfe2bd5a2355617ac1
Author: z3bra <willyatmailoodotorg>
Date:   Wed Dec 30 17:15:37 2015

Rely on stat(2) rather than strchr

stat(2) does a better job at checking if the given name is a
file name, or a pack name. Let's just use it.

Diffstat:
 pm.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/pm.c b/pm.c @@ -125,16 +125,18 @@ base_name(char *path) int inspect(char *name) { + struct stat st; + /* name is NULL, list packages installed */ if (!name) return list_local(1, PACKAGE_DATA); - /* if name contains a '/', assume it's an archive */ - if (strchr(name, '/')) - return list_archive(1, name); + /* if name isn't a filename, list installed files */ + if (stat(name, &st) < 0) + return list_content(1, name); - /* otherwise, list files installed by a package */ - return list_content(1, name); + /* otherwise, list the content of the pack */ + return list_archive(1, name); } /* @@ -504,12 +506,13 @@ struct pkg * pack_load(char *name) { struct pkg *p = NULL; + struct stat st; - if (strchr(name, '/')) - p = pack_load_file(name); - else + if (stat(name, &st) < 0) return NULL; + p = pack_load_file(name); + if (!p) { fprintf(stderr, "could not load package %s\n", name); return NULL;