package

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

commit 19177407141c63a6479fb89034d05ff7fc9e4c73
parent e710a0314322828cc717c4f6f7e5de06662eab5c
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 26 Jan 2019 21:40:20 +0100

fix permissions

allow files to be world readable and executable if needed

Diffstat:
Mhier.c | 22+++++++++++++++-------
Mpackage-build.c | 10+++++-----
Mpackage-get.c | 2+-
3 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/hier.c b/hier.c @@ -98,7 +98,7 @@ error: close(fd_from); } static int -hier_copy_recurse(stralloc *from, stralloc *to, int action) +hier_copy_recurse(stralloc *from, stralloc *to, int action, int mode) { DIR *dp = NULL; struct dirent *de; @@ -111,7 +111,7 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) 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 (mkdir(to->x, mode) == -1 && errno != EEXIST) goto error; if (!stralloc_cats(from, "/")) return 0; from_n = from->n; @@ -135,7 +135,7 @@ hier_copy_recurse(stralloc *from, stralloc *to, int action) if (lstat(from->x, &st) == -1) goto error; if (S_ISDIR(st.st_mode)) { - if (!hier_copy_recurse(from, to, action)) goto error; + if (!hier_copy_recurse(from, to, action, st.st_mode)) goto error; } else if (S_ISREG(st.st_mode)) { switch (action) { case 0: @@ -163,11 +163,15 @@ hier_copy(char const *from, char const *to) { stralloc sa_from = STRALLOC_ZERO; stralloc sa_to = STRALLOC_ZERO; + struct stat st; int ret = 0; - if (!stralloc_cats(&sa_from, from)) goto error; if (!stralloc_cats(&sa_to, to)) goto error; - ret = hier_copy_recurse(&sa_from, &sa_to, 0); + if (!stralloc_cats(&sa_from, from)) goto error; + if (!stralloc_cat0(&sa_from)) goto error; + sa_from.n--; + if (stat(sa_from.x, &st) == -1) goto error; + ret = hier_copy_recurse(&sa_from, &sa_to, 0, st.st_mode); error: stralloc_free(&sa_from); stralloc_free(&sa_to); @@ -179,11 +183,15 @@ hier_symlink(char const *from, char const *to) { stralloc sa_from = STRALLOC_ZERO; stralloc sa_to = STRALLOC_ZERO; + struct stat st; int ret = 0; - if (!stralloc_cats(&sa_from, from)) goto error; if (!stralloc_cats(&sa_to, to)) goto error; - ret = hier_copy_recurse(&sa_from, &sa_to, 1); + if (!stralloc_cats(&sa_from, from)) goto error; + if (!stralloc_cat0(&sa_from)) goto error; + sa_from.n--; + if (stat(sa_from.x, &st) == -1) goto error; + ret = hier_copy_recurse(&sa_from, &sa_to, 0, st.st_mode); error: stralloc_free(&sa_from); stralloc_free(&sa_to); diff --git a/package-build.c b/package-build.c @@ -175,25 +175,25 @@ main(int argc, char **argv) if (chdir(pkg) == -1) log_fatal_sys_2(101, "chdir ", pkg); - if (mkdir(p.name, 075) == -1 && errno != EEXIST) + if (mkdir(p.name, 0755) == -1 && errno != EEXIST) log_fatal_sys_4(101, "mkdir ", pkg, "/", p.name); if (chdir(p.name) == -1) log_fatal_sys_4(101, "chdir ", pkg, "/", p.name); - if (mkdir(p.ver, 075) == -1 && errno != EEXIST) + if (mkdir(p.ver, 0755) == -1 && errno != EEXIST) log_fatal_sys_6(101, "mkdir ", pkg, "/", p.name, "/", p.ver); if (chdir(p.ver) == -1) log_fatal_sys_6(101, "chdir ", pkg, "/", p.name, "/", p.ver); if ((x = open_read("source.tar")) == -1) log_fatal_sys_7(101, "open ", pkg, "/", p.name, "/", p.ver, "/source.tar"); - if (mkdir(id, 075) == -1 && errno != EEXIST) + if (mkdir(id, 0755) == -1 && errno != EEXIST) log_fatal_sys_8(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id); if (chdir(id) == -1) log_fatal_sys_8(101, "chdir ", pkg, "/", p.name, "/", p.ver, "/", id); if (close(1) == -1 || open_trunc("log") == -1) log_fatal_sys_9(101, "open ", pkg, "/", p.name, "/", p.ver, "/", id, "/log"); - if (mkdir("build", 075) == -1 && errno != EEXIST) + if (mkdir("build", 0755) == -1 && errno != EEXIST) log_fatal_sys_9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/build"); - if (mkdir("source", 075) == -1 && errno != EEXIST) + if (mkdir("source", 0755) == -1 && errno != EEXIST) log_fatal_sys_9(101, "mkdir ", pkg, "/", p.name, "/", p.ver, "/", id, "/source"); if (symlink(id, "latest") == -1 && errno != EEXIST) log_fatal_sys_9(101, "symlink ", pkg, "/", p.name, "/", p.ver, "/", id, "/latest"); diff --git a/package-get.c b/package-get.c @@ -69,7 +69,7 @@ main(int argc, char **argv) if (!stralloc_cats(&sa, "/")) die_nomem(); if (!stralloc_cats(&sa, p.ver)) die_nomem(); if (!stralloc_cat0(&sa)) die_nomem(); - if (!hier_mkdir(sa.x, 0750)) + if (!hier_mkdir(sa.x, 0755)) log_fatal_sys_2(101, "mkdir ", sa.x); if (chdir(sa.x) == -1) log_fatal_sys_2(101, "chdir ", sa.x);