package

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

commit c87c6153def76d08b8e72f4c5cc51f3771fa28c3
parent a5a090fb79c24a52f783094032fc1807fab3a86b
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 14:14:46 +0100

fix package-install

Diffstat:
MMakefile | 36++++++++++++++++++------------------
Mhier.c | 5++---
Mpackage-add.c | 8+++-----
Mpackage-get.c | 12+-----------
Mpackage-install.c | 46+++++++++++++++++++++++++++++++++++-----------
5 files changed, 59 insertions(+), 48 deletions(-)

diff --git a/Makefile b/Makefile @@ -35,22 +35,22 @@ package-install: package-install.o ${obj} .c.o: ./make-o $< -buffer.o: buffer.c buffer.h mem.h stralloc.h -fmt.o: fmt.c fmt.h str.h -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 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 +buffer.o: buffer.c buffer.h mem.h stralloc.h +fmt.o: fmt.c fmt.h str.h +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 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 lock.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 log.h stat.h hier.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 -str.o: str.c str.h -stralloc.o: stralloc.c mem.h fmt.h str.h stralloc.h -tai.o: tai.c tai.h -tain.o: tain.c tain.h uint64.h fmt.h -uint64.o: uint64.c uint64.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 tai.h +stat.o: stat.c stat.h +str.o: str.c str.h +stralloc.o: stralloc.c mem.h fmt.h str.h stralloc.h +tai.o: tai.c tai.h +tain.o: tain.c tain.h uint64.h fmt.h +uint64.o: uint64.c uint64.h diff --git a/hier.c b/hier.c @@ -35,11 +35,10 @@ hier_remove_recurse(stralloc *sa) struct stat st; size_t n = sa->n; - dp = opendir(sa->x); if (dp == NULL) return 0; - if (!stralloc_cats(sa, "/")) return 0; n = sa->n; + dp = opendir(sa->x); if (dp == NULL) return 0; errno = 0; while ((de = readdir(dp))) { if (str_equal(de->d_name, ".")) continue; @@ -114,7 +113,6 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) to_n = to->n; dp = opendir(from->x); if (!dp) return 0; - errno = 0; while ((de = readdir(dp))) { if (str_equal(de->d_name, ".")) continue; @@ -138,6 +136,7 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) if (!copy(from->x, to->x, st.st_mode)) goto end; break; case 1: + unlink(to->x); if (symlink(from->x, to->x) == -1) goto end; break; } diff --git a/package-add.c b/package-add.c @@ -66,8 +66,6 @@ main(int argc, char **argv) char const *argv[] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; int x; - log_info_5("[ ", p->name, "/", p->ver, " ]"); - fmt[package_fmt(p, fmt)] = '\0'; argv[1] = "-d"; @@ -96,15 +94,15 @@ main(int argc, char **argv) if (!stralloc_cat0(&sa)) die_nomem(); if (stat_isfile(sa.x)) goto build; - log_info_1("package-get"); + log_info_4("package-get ", p->name, "/", p->ver); argv[0] = "package-get"; if ((x = forkexec_wait(argv)) != 0) goto error; build: - log_info_1("package-build"); + log_info_4("package-build ", p->name, "/", p->ver); argv[0] = "package-build"; if ((x = forkexec_wait(argv)) != 0) goto error; install: - log_info_1("package-install"); + log_info_4("package-install ", p->name, "/", p->ver); argv[0] = "package-install"; if ((x = forkexec_wait(argv)) != 0) goto error; diff --git a/package-get.c b/package-get.c @@ -18,13 +18,6 @@ die_nomem(void) log_fatal_sys_1(100, "malloc"); } -void -usage(char const *argv_0, char const *param) -{ - log_error_2("missing parameter: ", param); - log_usage(argv_0, "-p pkgdir -d defdir packageage[/version]"); -} - int main(int argc, char **argv) { @@ -48,10 +41,7 @@ main(int argc, char **argv) break; } - if (!def) usage(*argv, "-d"); - if (!pkg) usage(*argv, "-p"); - if (!*av) usage(*argv, "packageage[/version]"); - + if (!*av) log_usage(*argv, "packageage[/version]"); if (!stat_isdir(def)) log_fatal_sys_1(101, def); n = package_scan(&p, *av); diff --git a/package-install.c b/package-install.c @@ -1,3 +1,5 @@ +#include <errno.h> + #include "package.h" #include "log.h" #include "stat.h" @@ -26,7 +28,8 @@ int main(int argc, char **argv) { package p; - stralloc sa; + stralloc sa_pkg; + stralloc sa_root; char *def = PACKAGE_DEF; char *pkg = PACKAGE_DIR; char *root = PACKAGE_ROOT; @@ -54,17 +57,38 @@ main(int argc, char **argv) if (!package_version(&p, def)) log_fatal_sys_2(101, "version ", p.name); - stralloc_init(&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(); + stralloc_init(&sa_pkg); + if (!stralloc_cats(&sa_pkg, pkg)) die_nomem(); + if (!stralloc_cats(&sa_pkg, "/")) die_nomem(); + if (!stralloc_cats(&sa_pkg, p.name)) die_nomem(); + if (!stralloc_cats(&sa_pkg, "/")) die_nomem(); + if (!stralloc_cats(&sa_pkg, p.ver)) die_nomem(); + if (!stralloc_cats(&sa_pkg, "/current/build/bin")) die_nomem(); + if (!stralloc_cat0(&sa_pkg)) die_nomem(); + stralloc_init(&sa_root); + if (!stralloc_cats(&sa_root, root)) die_nomem(); + if (!stralloc_cats(&sa_root, "/bin")) die_nomem(); + if (!stralloc_cat0(&sa_root)) die_nomem(); + errno = 0; + if (!hier_symlink(sa_pkg.x, sa_root.x) && errno != ENOENT) + log_fatal_sys_4(102, "symlink ", sa_pkg.x, " ", sa_root.x); + + sa_pkg.n -= 4; + if (!stralloc_cats(&sa_pkg, "man")) die_nomem(); + if (!stralloc_cat0(&sa_pkg)) die_nomem(); + sa_root.n -= 4; + if (!stralloc_cats(&sa_root, "man")) die_nomem(); + if (!stralloc_cat0(&sa_root)) die_nomem(); + errno = 0; + if (!hier_symlink(sa_pkg.x, sa_root.x) && errno != ENOENT) + log_fatal_sys_4(102, "symlink ", sa_pkg.x, " ", sa_root.x); - if (hier_symlink(sa.x, root) == -1) - log_fatal_sys_4(102, "symlink ", sa.x, " ", root); + sa_pkg.n -= 4; + if (!stralloc_cats(&sa_pkg, "share/man")) die_nomem(); + if (!stralloc_cat0(&sa_pkg)) die_nomem(); + errno = 0; + if (!hier_symlink(sa_pkg.x, sa_root.x) && errno != ENOENT) + log_fatal_sys_4(102, "symlink ", sa_pkg.x, " ", sa_root.x); return 0; }