pm

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

commit cf0441277b56ecaae38641dfe2bd5a2355617ac1
parent a90605e2b376486576007c7acb6967ca3af0823f
Author: z3bra <willyatmailoodotorg>
Date:   Wed Dec 30 17:02:41 2015

Include version number in metadata

Diffstat:
 pm.c | 56 ++++++++++++++++++++++++++++++++++++++++++--------------
 1 file changed, 42 insertions(+), 14 deletions(-)

diff --git a/pm.c b/pm.c @@ -49,7 +49,7 @@ int inspect(char *name); int list_archive(int fd, char *filename); int list_local(int fd, char *packname); int list_content(int fd, char *packname); -int metadata(char *datadir, char *filename); +int metadata(char *datadir, struct pkg *pack); int pack(char *out, char **filename); int unpack(char *root, char *in); int delete_content(FILE *metafile); @@ -200,6 +200,9 @@ list_local(int fd, char *datadir) { DIR *d; struct dirent *p; + char tmp[PATH_MAX]; + int meta; + size_t len; if (!(d = opendir(datadir))) { perror("opendir"); @@ -207,8 +210,19 @@ list_local(int fd, char *datadir) } while ((p = readdir(d))) - if (strcmp(p->d_name, ".") && strcmp(p->d_name, "..")) - dprintf(fd, "%s\n", p->d_name); + if (strcmp(p->d_name, ".") && strcmp(p->d_name, "..")) { + snprintf(tmp, PATH_MAX, "%s/%s/version", + datadir, p->d_name); + + if ((meta = open(tmp, O_RDONLY)) < 0) { + perror("open"); + closedir(d); + return (1); + } + len = read(meta, tmp, 32); + tmp[len - 1] = 0; + dprintf(fd, "%s\t%s\n", p->d_name, tmp); + } closedir(d); return 0; @@ -219,16 +233,16 @@ list_local(int fd, char *datadir) * write metadata about a package file * * TODO: - * + /deps /asdep /version + * + /deps /asdep */ int -metadata(char *datadir, char *filename) +metadata(char *datadir, struct pkg *pack) { int fd, r; struct stat st; char tmp[PATH_MAX], *name; - name = strdup(filename); + name = strdup(pack->path); name = strtok(name, ":"); sprintf(tmp, "%s/%s", datadir, base_name(name)); @@ -240,15 +254,26 @@ metadata(char *datadir, char *filename) return r; } - strncat(tmp, "/files", PATH_MAX); + snprintf(tmp, PATH_MAX, "%s/%s/files", datadir, pack->name); fd = open(tmp, O_CREAT|O_WRONLY|O_TRUNC, 0644); - if (fd > 0) { - list_archive(fd, filename); - close(fd); - return 0; + if (fd < 0) { + perror("open"); + return -1; } + list_archive(fd, pack->path); + close(fd); - return -1; + snprintf(tmp, PATH_MAX, "%s/%s/version", datadir, pack->name); + fd = open(tmp, O_CREAT|O_WRONLY|O_TRUNC, 0644); + if (fd < 0) { + perror("open"); + return -1; + } + write(fd, pack->version, strlen(pack->version)); + write(fd, "\n", 1); + close(fd); + + return 0; } /* @@ -405,8 +430,10 @@ delete(const char *datadir, const char *rootfs, const char *name) FILE *f; char meta[PATH_MAX]; - snprintf(meta, PATH_MAX, "%s/%s/files", datadir, name); + snprintf(meta, PATH_MAX, "%s/%s/version", datadir, name); + unlink(meta); + snprintf(meta, PATH_MAX, "%s/%s/files", datadir, name); if ((f = fopen(meta, "r")) == NULL) { perror("fopen"); return -1; @@ -426,6 +453,7 @@ delete(const char *datadir, const char *rootfs, const char *name) chdir(cwd); unlink(meta); + snprintf(meta, PATH_MAX, "%s/%s", datadir, name); rmdir(meta); @@ -525,7 +553,7 @@ main (int argc, char **argv) case ACTION_INSTALL: if (!p) return ERR_PACKAGE_LOAD; - if (metadata(PACKAGE_DATA, p->path) == 0) + if (metadata(PACKAGE_DATA, p) == 0) return unpack(PACKAGE_ROOT, p->path); fprintf(stderr, "could not write metadata for %s\n", p->name); return ERR_METADATA;