pm

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

commit fb204995f7751e8a1e834455275fbaa2f44f7bab
parent 0979ad3342b23c9292a7effb32790d1ef6764468
Author: z3bra <willyatmailoodotorg>
Date:   Wed Dec 30 15:57:32 2015

List files installed by a package

Diffstat:
 pm.c | 36 ++++++++++++++++++++++++++++++++----
 1 file changed, 32 insertions(+), 4 deletions(-)

diff --git a/pm.c b/pm.c @@ -51,6 +51,7 @@ 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 list_content(const char *name); int metadata(char *datadir, char *filename); int pack(char *out, char **filename); int unpack(char *root, char *in); @@ -177,6 +178,27 @@ list_local(const char *datadir) } /* + * List files installed by a package + */ +int +list_content(const char *name) +{ + int fd; + char tmp[PATH_MAX]; + + snprintf(tmp, PATH_MAX, "%s/%s/files", PACKAGE_DATA, name); + if ((fd = open(tmp, O_RDONLY)) < 0) { + perror("open"); + return -1; + } + + while (read(fd, tmp, LINE_MAX)) + printf("%s", tmp); + + return 0; +} + +/* * write metadata about a package file * * TODO: @@ -475,7 +497,12 @@ main (int argc, char **argv) n = EARGF(usage(argv0)); break; case 'l': - action = ACTION_LIST_LOCAL; + if (argc > 1) { + action = ACTION_LIST_FILES; + n = ARGF(); + } else { + action = ACTION_LIST_LOCAL; + } break; case 'r': action = ACTION_DELETE; @@ -498,6 +525,8 @@ main (int argc, char **argv) return unpack(PACKAGE_ROOT, p->path); fprintf(stderr, "could not write metadata for %s\n", p->name); return ERR_METADATA; + case ACTION_DELETE: + return delete(PACKAGE_DATA, PACKAGE_ROOT, n); case ACTION_INSPECT: if (!p) return ERR_PACKAGE_LOAD; @@ -508,11 +537,10 @@ main (int argc, char **argv) return pack(p->path, argv); case ACTION_LIST_LOCAL: return list_local(PACKAGE_DATA); - case ACTION_DELETE: - return delete(PACKAGE_DATA, PACKAGE_ROOT, n); + case ACTION_LIST_FILES: + return list_content(n); /* handle me, Octave */ case ACTION_UPDATE: - case ACTION_LIST_FILES: case ACTION_LIST_DEPS: case ACTION_LIST_REMOTE: default: