pm

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

commit b1f152ac97a08e6bc3c5c401a36228643ce77672
parent 4cddf9af68b6e22c51621a9c04159a266f23adc5
Author: z3bra <willyatmailoodotorg>
Date:   Wed Dec 30 12:11:29 2015

List package installed

Diffstat:
 pm.c | 35 ++++++++++++++++++++++++++++++-----
 1 file changed, 30 insertions(+), 5 deletions(-)

diff --git a/pm.c b/pm.c @@ -1,3 +1,4 @@ +#include <dirent.h> #include <fcntl.h> #include <limits.h> #include <stdio.h> @@ -48,6 +49,7 @@ void usage(char *name); int p_mkdir(char *dir, mode_t mode); char *base_name(char *path); int inspect(int fd, char *filename); +int list_local(const char *datadir); int metadata(char *datadir, char *filename); int pack(char *out, char **filename); int unpack(char *root, char *in); @@ -128,6 +130,25 @@ inspect(int fd, char *filename) return 0; } + +int +list_local(const char *datadir) +{ + DIR *d; + struct dirent *p; + + if (!(d = opendir(datadir))) { + perror("opendir"); + return -1; + } + + while ((p = readdir(d))) + if (strcmp(p->d_name, ".") && strcmp(p->d_name, "..")) + printf("%s\n", p->d_name); + + return 0; +} + /* * write metadata about a package file * @@ -353,17 +374,20 @@ main (int argc, char **argv) action = ACTION_INSPECT; fn = EARGF(usage(argv0)); break; + case 'l': + action = ACTION_LIST_LOCAL; + break; case 'h': default: usage(argv0); return 0; }ARGEND; - if (fn) + if (fn) { p = pack_load(fn); - - if (!p) - return ERR_PACKAGE_LOAD; + if (!p) + return ERR_PACKAGE_LOAD; + } switch (action) { case ACTION_INSTALL: @@ -375,12 +399,13 @@ main (int argc, char **argv) return inspect(1, p->path); case ACTION_PACKAGE: return pack(p->path, argv); + case ACTION_LIST_LOCAL: + return list_local(PACKAGE_DATA); /* handle me, Octave */ case ACTION_REMOVE: case ACTION_UPDATE: case ACTION_LIST_FILES: case ACTION_LIST_DEPS: - case ACTION_LIST_LOCAL: case ACTION_LIST_REMOTE: default: usage(argv0);