pm

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

commit b5a2a221b195030cfc21db7696651860f9ec535c
parent fbd4d728ef17718ed7ee6ac2629ac3913111ff79
Author: z3bra <willyatmailoodotorg>
Date:   Wed Dec 23 11:22:19 2015

Write metadata during package installation

Diffstat:
 pm.c | 53 ++++++++++++++++++++++++++++++++++++++++++++++-------
 1 file changed, 46 insertions(+), 7 deletions(-)

diff --git a/pm.c b/pm.c @@ -1,6 +1,8 @@ #include <fcntl.h> +#include <limits.h> #include <stdio.h> #include <stdlib.h> +#include <string.h> #include <sys/stat.h> #include <sys/types.h> @@ -10,6 +12,7 @@ #include "arg.h" #define PACKAGE_ROOT_DIR "." +#define PACKAGE_DATA_DIR "./metadata" #define PACKAGE_BUFF_SIZE 8192 /* possible actions */ @@ -27,7 +30,8 @@ enum { }; enum { - ERROR_INVALID_ACTION = 1, + ERR_INVALID_ACTION = 1, + ERR_METADATA = 2, }; char *argv0; @@ -39,10 +43,10 @@ usage(char *name) } /* - * output the content of an archive + * write the content of an archive to the given file descriptor */ int -inspect(const char *filename) +inspect(int fd, const char *filename) { struct archive *a; struct archive_entry *e; @@ -60,7 +64,7 @@ inspect(const char *filename) /* output each filename to stdout */ while(archive_read_next_header(a, &e) == ARCHIVE_OK) { - puts(archive_entry_pathname(e)); + dprintf(fd, "%s\n", archive_entry_pathname(e)); } r = archive_read_free(a); @@ -71,6 +75,38 @@ inspect(const char *filename) } /* + * write metadata about a package file + * + * TODO: + * + subdir for package name + * + recursive mkdir + * + /deps /asdep /version + */ +int +metadata(const char *datadir, const char *filename) +{ + int fd, r; + char tmp[PATH_MAX]; + + strncpy(tmp, datadir, PATH_MAX); + strncat(tmp, "/files", PATH_MAX); + + r = mkdir(datadir, 0750); + if (r < 0) + return r; + + fd = open(tmp, O_CREAT|O_WRONLY|O_TRUNC, 0644); + + if (fd > 0) { + inspect(fd, filename); + close(fd); + return 0; + } + + return -1; +} + +/* * pack mutliple files into an archive */ int @@ -211,9 +247,12 @@ main (int argc, char **argv) switch (action) { case ACTION_INSTALL: - return unpack(PACKAGE_ROOT_DIR, packname); + if (metadata(PACKAGE_DATA_DIR, packname) == 0) + return unpack(PACKAGE_ROOT_DIR, packname); + fprintf(stderr, "could not write metadata for %s\n", packname); + return ERR_METADATA; case ACTION_INSPECT: - return inspect(packname); + return inspect(1, packname); case ACTION_PACKAGE: return pack(packname, argv); /* handle me, Octave */ @@ -225,7 +264,7 @@ main (int argc, char **argv) case ACTION_LIST_REMOTE: default: usage(argv0); - exit(ERROR_INVALID_ACTION); + return ERR_INVALID_ACTION; } return 0;