package

simple and robust package manager
Log | Files | Refs | README

commit 8f90967e6dc0b30feb66818b8b6b05d1f3cf1d32
parent 6e2304848bc06c489da36a2ba53ffe1c4538613f
Author: Josuah Demangeon <mail@josuah.net>
Date:   Thu, 17 Jan 2019 01:15:49 +0100

add a trivial simple package-add that works

Diffstat:
MMakefile | 5+++--
Apackage-add | 0
Mpackage-add.c | 131+++++++++++++++++++++++++++++++++++++++++++++++++------------------------------
Mpackage-build | 0
Mpackage-dep | 0
Mpackage-get | 0
Mpackage-tree | 0
Mstat.c | 2+-
8 files changed, 85 insertions(+), 53 deletions(-)

diff --git a/Makefile b/Makefile @@ -1,4 +1,4 @@ -bin = package-build package-dep package-get package-tree # package-add +bin = package-build package-dep package-get package-tree package-add obj = package.o buffer.o fmt.o stat.o hier.o log.o mem.o str.o stralloc.o forkexec.o tai.o tain.o .PHONY: all @@ -38,10 +38,11 @@ forkexec.o: forkexec.c open.h forkexec.h hier.o: hier.c hier.h open.h str.h stralloc.h log.o: log.c buffer.h log.h mem.o: mem.c mem.h -package-add.o: package-add.c buffer.h env.h fmt.h genalloc.h log.h open.h package.h stat.h str.h +package-add.o: package-add.c buffer.h fmt.h genalloc.h log.h package.h stat.h str.h forkexec.h package-build.o: package-build.c buffer.h env.h fmt.h forkexec.h hier.h hier.h log.h open.h package.h stat.h str.h stralloc.h tain.h package-dep.o: package-dep.c buffer.h env.h stat.h genalloc.h log.h package.h str.h package-get.o: package-get.c buffer.h env.h forkexec.h hier.h lock.h log.h open.h package.h stat.h stralloc.h +package-install.o: package-install.c package.h package-tree.o: package-tree.c buffer.h env.h log.h open.h package.h stat.h stralloc.h package.o: package.c buffer.h env.h fmt.h forkexec.h genalloc.h mem.h open.h package.h stralloc.h lock.h tai.h stat.o: stat.c stat.h diff --git a/package-add b/package-add Binary files differ. diff --git a/package-add.c b/package-add.c @@ -3,99 +3,130 @@ #include <unistd.h> #include "buffer.h" -#include "env.h" #include "fmt.h" #include "genalloc.h" #include "log.h" -#include "open.h" #include "package.h" #include "stat.h" #include "str.h" +#include "forkexec.h" void -die_nomem(void) +usage(char *argv0) { - log_diesys1(100, "malloc"); + log_usage(argv0, "-p pkgdir -d defdir packageage[/version]"); } void -step(package const *p, char const *cmd char const *dir, char const *sub) +die_nomem(void) { - int x; - char fmt[4]; - - buffer_puts(buffer_2, " "); - buffer_puts(buffer_2, sub); - buffer_puts(buffer_2, " "); - buffer_flush(buffer_2); - - if ((x = package_step(p, cmd, log, dir, sub)) == 0) return; - - fmt_long(fmt, x); - buffer_puts(buffer_2, "< exit "); - buffer_puts(buffer_2, fmt); - buffer_puts(buffer_2, "\n"); - buffer_flush(buffer_2); - - if (dir && !package_remove(p, dir, char const *sub)) - log_errsys6("deleting .../", sub, "/", p->name, "/", p->ver); - exit(100); + log_diesys1(100, "malloc"); } int main(int argc, char **argv) { genalloc ga; - size_t i; + size_t n; package p; - char *dir; - char *def; + char *pkg = PACKAGE_DIR; + char *def = PACKAGE_DEF; + char **av = argv; - if (argc != 2) log_usage(*argv, "packageage[/version]"); - ++argv; + (void)argc; + + while (*++av) { + if (str_equal(*av, "-d")) { if (!(def = *++av)) break; continue; } + if (str_equal(*av, "-p")) { if (!(pkg = *++av)) break; continue; } + break; + } - dir = env_get("PACKAGE_DIR"); if (!dir) dir = PACKAGE_DIR; - def = env_get("PACKAGE_DEF"); if (!def) def = PACKAGE_DEF; + if (!*av) usage(*argv); if (!stat_isdir(def)) log_diesys1(101, def); + if (!stat_isdir(pkg)) log_diesys1(101, pkg); - i = package_scan(&p, *argv); - if (i == 0 || (*argv)[i] != '\0') - log_die2(1, "invalid packageage name: ", *argv); + n = package_scan(&p, *av); + if (n == 0 || (*av)[n] != '\0') + log_die2(1, "invalid packageage name: ", *av); if (!package_version(&p, def)) - log_diesys3(101, "could not get ", *argv," version"); + log_diesys3(101, "could not get ", *av," version"); genalloc_init(&ga); if (!package_dep(&p, &ga, def)) log_diesys1(103, "could not resolve packageage dependencies"); if (!genalloc_append(&ga, p)) die_nomem(); - for (i = 0; i < genalloc_len(&ga, package); ++i) + for (size_t i = 0; i < genalloc_len(&ga, package); ++i) { + stralloc sa = STRALLOC_ZERO; package *p = genalloc_get(&ga, package, i); char fmt[PACKAGE_FMT + 80]; + char const *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; + int x; buffer_puts(buffer_2, " "); - fmt_fill(fmt, sizeof fmt, p->name, 25); - buffer_puts(buffer_2, fmt); - buffer_puts(buffer_2, " "); - fmt_fill(fmt, sizeof fmt, p->ver, 10); - buffer_puts(buffer_2, fmt); + buffer_puts(buffer_2, p->name); buffer_puts(buffer_2, " "); + buffer_puts(buffer_2, p->ver); + buffer_puts(buffer_2, "\n"); buffer_flush(buffer_2); - if (package_isdone(p, dir, "run")) goto step_install; - if (package_isdone(p, dir, "src")) goto step_build; - if (package_isdone(p, dir, "tar")) goto step_tar; + fmt[package_fmt(p, fmt)] = '\0'; + + argv[1] = "-d"; + argv[2] = def; + argv[3] = "-p"; + argv[4] = pkg; + argv[5] = fmt; + + stralloc_zero(&sa); + if (!stralloc_cats(&sa, pkg)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p->name)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p->ver)) die_nomem(); + if (!stralloc_cats(&sa, "/current")) die_nomem(); + if (!stralloc_cat0(&sa)) die_nomem(); + if (stat_islink(sa.x)) goto install; + + stralloc_zero(&sa); + if (!stralloc_cats(&sa, pkg)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p->name)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + if (!stralloc_cats(&sa, p->ver)) die_nomem(); + if (!stralloc_cats(&sa, "/source.tar")) die_nomem(); + if (!stralloc_cat0(&sa)) die_nomem(); + if (stat_isfile(sa.x)) goto build; + + buffer_puts(buffer_2, " package-get ....... "); + buffer_flush(buffer_2); + argv[0] = "package-get"; + if ((x = forkexec_wait(argv)) != 0) goto error; + buffer_puts(buffer_2, "ok\n"); + buffer_flush(buffer_2); +build: + buffer_puts(buffer_2, " package-build ..... "); + buffer_flush(buffer_2); + argv[0] = "package-build"; + if ((x = forkexec_wait(argv)) != 0) goto error; + buffer_puts(buffer_2, "ok\n"); + buffer_flush(buffer_2); +install: + buffer_puts(buffer_2, " package-install ... "); + buffer_flush(buffer_2); + argv[0] = "package-install"; + if ((x = forkexec_wait(argv)) != 0) goto error; + buffer_puts(buffer_2, "ok\n"); + buffer_flush(buffer_2); - step(p, "package-get", log, tar); -step_build: - step(p, "package-build", log, out); -step_install: - step(p, "package-install", log, NULL); - buffer_puts(buffer_2, "\n"); + continue; +error: + buffer_puts(buffer_2, "error\n"); buffer_flush(buffer_2); + return x; } genalloc_free(&ga); diff --git a/package-build b/package-build Binary files differ. diff --git a/package-dep b/package-dep Binary files differ. diff --git a/package-get b/package-get Binary files differ. diff --git a/package-tree b/package-tree Binary files differ. diff --git a/stat.c b/stat.c @@ -14,7 +14,7 @@ int stat_islink(char const *path) { struct stat st; - if (stat(path, &st) == -1) return 0; + if (lstat(path, &st) == -1) return 0; return S_ISLNK(st.st_mode); }