package

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

commit 6842cd57815cba3a268b932bef4adbce83895983
parent 629e4c29fdf5f85a13d2dbc43f88f00cec46eab2
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 19 Jan 2019 18:41:35 +0100

source dressing cleanups

Diffstat:
Mhier.c | 40+++++++++++++++++++++++-----------------
Mpackage-build.c | 2+-
2 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/hier.c b/hier.c @@ -106,10 +106,12 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) char ln[4096]; size_t to_n = to->n; size_t from_n = from->n; + int ret = 0; if (!stralloc_cats(from, "/")) return 0; - if (!stralloc_cats(to, "/")) return 0; from_n = from->n; + + if (!stralloc_cats(to, "/")) return 0; to_n = to->n; dp = opendir(from->x); if (!dp) return 0; @@ -118,36 +120,40 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) if (str_equal(de->d_name, ".")) continue; if (str_equal(de->d_name, "..")) continue; - to->n = to_n; - if (!stralloc_cats(to, de->d_name)) break; - if (!stralloc_cat0(to)) break; - from->n = from_n; - if (!stralloc_cats(from, de->d_name)) break; - if (!stralloc_cat0(from)) break; + if (!stralloc_cats(from, de->d_name)) goto err; + if (!stralloc_cat0(from)) goto err; + from->n--; + + to->n = to_n; + if (!stralloc_cats(to, de->d_name)) goto err; + if (!stralloc_cat0(to)) goto err; + to->n--; - if (lstat(from->x, &st) == -1) break; + if (lstat(from->x, &st) == -1) goto err; if (S_ISDIR(st.st_mode)) { - if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) break; - if (!hier_copy_recurse(from, to, action)) break; + if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) goto err; + if (!hier_copy_recurse(from, to, action)) goto err; } else if (S_ISREG(st.st_mode)) { switch (action) { case 0: - if (!copy(from->x, to->x, st.st_mode)) goto end; + if (!copy(from->x, to->x, st.st_mode)) goto err; break; case 1: unlink(to->x); - if (symlink(from->x, to->x) == -1) goto end; + if (symlink(from->x, to->x) == -1) goto err; break; } } else if (S_ISLNK(st.st_mode)) { - if (readlink(from->x, ln, sizeof ln) == -1) break; - if (symlink(ln, to->x) == -1) break; - } else break; + unlink(to->x); + if (readlink(from->x, ln, sizeof ln) == -1) goto err; + if (symlink(ln, to->x) == -1) goto err; + } else goto err; } -end: + ret = 1; +err: closedir(dp); - return errno == 0; + return ret; } int diff --git a/package-build.c b/package-build.c @@ -294,7 +294,7 @@ main(int argc, char **argv) write(1, "\n=== copy ===\n", 14); if (!copy(&p, def)) - log_fatal_sys_9(100, "copy ", def, "/", p.name, "/", p.ver, "/", id, "/source"); + log_fatal_sys_9(100, "copy ", pkg, "/", p.name, "/", p.ver, "/", id, "/source"); write(1, "=== end ===\n", 12); write(1, "\n=== setenv ===\n", 16);