package

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

commit e710a0314322828cc717c4f6f7e5de06662eab5c
parent c480354624cdca89169d2fa099e38dc8a25d43f4
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 26 Jan 2019 20:18:31 +0100

everything from the /package/<name>/<ver>/<build>/build/* dir get installed

Diffstat:
Mhier.c | 15++++++++-------
Mpackage-install.c | 28+++-------------------------
2 files changed, 11 insertions(+), 32 deletions(-)

diff --git a/hier.c b/hier.c @@ -100,7 +100,7 @@ error: close(fd_from); static int hier_copy_recurse(stralloc *from, stralloc *to, int action) { - DIR *dp; + DIR *dp = NULL; struct dirent *de; struct stat st; char ln[4096]; @@ -108,14 +108,16 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) size_t from_n = from->n; int ret = 0; - if (!stralloc_cats(from, "/")) return 0; - from_n = from->n; - if (!stralloc_cats(to, "/")) return 0; to_n = to->n; + if (!stralloc_cat0(to)) return 0; + if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) goto error; + if (!stralloc_cats(from, "/")) return 0; + from_n = from->n; if (!stralloc_cat0(from)) return 0; - dp = opendir(from->x); if (!dp) return 0; + if (!(dp = opendir(from->x))) return 0; + errno = 0; while ((de = readdir(dp))) { if (str_equal(de->d_name, ".")) continue; @@ -133,7 +135,6 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) if (lstat(from->x, &st) == -1) goto error; if (S_ISDIR(st.st_mode)) { - if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) goto error; if (!hier_copy_recurse(from, to, action)) goto error; } else if (S_ISREG(st.st_mode)) { switch (action) { @@ -153,7 +154,7 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) } ret = 1; error: - closedir(dp); + if (dp) closedir(dp); return ret; } diff --git a/package-install.c b/package-install.c @@ -16,7 +16,6 @@ main(int argc, char **argv) { package p; stralloc sa_pkg; - stralloc sa_root; char *def = PACKAGE_DEF; char *pkg = PACKAGE_DIR; char *root = PACKAGE_ROOT; @@ -43,32 +42,11 @@ main(int argc, char **argv) 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_cats(&sa_pkg, "/current/build")) 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); - - 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); + if (!hier_symlink(sa_pkg.x, root) && errno != ENOENT) + log_fatal_sys_4(102, "symlink ", sa_pkg.x, " ", root); return 0; }