package

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

commit 44e1251700b687990acff226a6044044979b007f
parent df29b1376eddb3ee63f68680a43d8d073ea8c1d4
Author: Josuah Demangeon <mail@josuah.net>
Date:   Sat, 12 Jan 2019 17:31:59 +0100

add a pack-add that calls the other binaries

Diffstat:
M.gitignore | 1+
MMakefile | 6+++++-
Dbin/pack-add | 28----------------------------
Mbin/pack-get | 4++--
Mbin/pack-tar | 6++++--
Mfmt.c | 48+++++++++++++++++++++++++++---------------------
Mfmt.h | 4++--
Mforkexec.c | 25++++++++++++++++++++++++-
Mforkexec.h | 3++-
Mfs.c | 55+++++++++++++++++++++++++++++++++++++++++--------------
Mfs.h | 17++++++++++-------
Mpack-add.c | 148++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
Mpack-build.c | 7+++----
Mpack-dep.c | 80++++++++++++-------------------------------------------------------------------
Mpack.c | 66+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-----
Mpack.h | 3+++
Mstr.c | 4++--
Mstr.h | 2+-
18 files changed, 347 insertions(+), 160 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -1,4 +1,5 @@ *.o *.core pack-build +pack-add pack-dep diff --git a/Makefile b/Makefile @@ -1,5 +1,5 @@ .PHONY: all -all: pack-build pack-dep +all: pack-build pack-dep pack-add .PHONY: clean clean: @@ -19,6 +19,10 @@ pack-dep-o = pack-dep.o pack.o buffer.o fmt.o fs.o log.o mem.o str.o stralloc.o pack-dep: ${pack-dep-o} ./make-bin $@ ${pack-dep-o} +pack-add-o = pack-add.o pack.o buffer.o fmt.o fs.o log.o mem.o str.o stralloc.o forkexec.o +pack-add: ${pack-add-o} + ./make-bin $@ ${pack-add-o} + .c.o: ./make-o $< diff --git a/bin/pack-add b/bin/pack-add @@ -1,28 +0,0 @@ -#!/bin/sh -e -PACK_LOG=${PACK_LOG:-/var/log/pack} - -test $# -gt 0 - -trap echo INT TERM EXIT - -pack-dep "$@" | while IFS=/ read -r pack version; do - printf ' %-30s %-15s' "$pack" "$version" - - mkdir -p "$PACK_LOG/$pack/$version" - - printf ' get ' - pack-get "$pack" "$version" >$PACK_LOG/$pack/$version/get 2>&1 - - printf ' tar ' - pack-tar "$pack" "$version" >$PACK_LOG/$pack/$version/tar 2>&1 - - printf ' build ' - pack-build "$pack/$version" >$PACK_LOG/$pack/$version/build 2>&1 - - printf ' install ' - pack-install "$pack" "$version" >$PACK_LOG/$pack/$version/install 2>&1 - - echo -done - -trap - INT TERM EXIT diff --git a/bin/pack-get b/bin/pack-get @@ -1,8 +1,8 @@ #!/bin/sh -e PACK=${PACK:-/var/pack} IFS=/; set -- $1; IFS= -pack=$1 -version=${2:-$(sed q "/etc/pack/$1/default/version")} +pack=${1%/*} +version=${2#*/} if [ -d "$PACK/src/$pack/$version" ]; then exit 0; fi mkdir -p "$PACK/log/$pack/$version" diff --git a/bin/pack-tar b/bin/pack-tar @@ -1,6 +1,8 @@ #!/bin/sh -e -PACK=${PACK:-/var/pack} -pack=$1 version=${2:-$(sed q "/etc/pack/$1/version")} +PACK_SRC=${PACK_SRC:-/var/pack/src} +PACK_TAR=${PACK_TAR:-/var/pack/tar} +pack=${1%/*} +version=${2#*/} trap "rm -rf '$PACK/src/$pack/$version'" EXIT TERM INT diff --git a/fmt.c b/fmt.c @@ -15,20 +15,6 @@ fmt_8long(char *buf, unsigned long i) return n; } -/* "foo" -> "foo " */ -size_t -fmt_fill(char* dest, size_t srclen, size_t padlen, size_t maxlen) -{ - size_t n; - - n = maxlen < padlen ? srclen : padlen < srclen ? srclen : padlen; - if (!dest) return n; - - dest += n; - for (n = srclen; n < maxlen && n < padlen; n++) *dest++ = ' '; - return n; -} - size_t fmt_long(char *dest, long i) { @@ -48,18 +34,38 @@ fmt_minus(char *dest, int i) return 1; } +/* "foo" -> "foo " */ +size_t +fmt_fill(char *dest, size_t size, char const *src, size_t fill) +{ + size_t n = 0; + size_t max; + size_t srclen = str_len(src); + + if (!dest) return srclen > fill ? srclen : fill; + + max = size < srclen ? size : srclen; + while (n < max) dest[n++] = *src++; + while (n < fill) dest[n++] = ' '; + dest[n] = '\0'; + + return n; +} + /* "foo" -> " foo" */ size_t -fmt_pad(char *dest, char const *src, size_t srclen, size_t padlen, size_t maxlen) +fmt_pad(char *dest, size_t size, char const *src, size_t pad) { - size_t n, max; + size_t n = 0; + size_t max; + size_t srclen = str_len(src); - if (!dest) return maxlen < padlen ? maxlen : padlen < srclen ? srclen : padlen; + if (!dest) return srclen > pad ? srclen : pad; - n = 0; - max = maxlen < srclen ? maxlen : srclen; - for (; n < padlen - srclen; ++n) *dest++ = ' '; - for (; n < max; ++n) *dest++ = *src++; + max = size < pad + srclen ? size : pad + srclen; + while (n++ < pad - srclen) *dest++ = ' '; + while (n++ < max) *dest++ = *src++; + dest[n] = '\0'; return n; } diff --git a/fmt.h b/fmt.h @@ -5,10 +5,10 @@ #include <stdint.h> size_t fmt_8long(char *, unsigned long); -size_t fmt_fill(char*, size_t, size_t, size_t); +size_t fmt_fill(char *, size_t, char const *, size_t); size_t fmt_long(char *, long); size_t fmt_minus(char *, int); -size_t fmt_pad(char *, char const *, size_t, size_t, size_t); +size_t fmt_pad(char *, size_t, char const *, size_t); size_t fmt_plusminus(char *, int); size_t fmt_strn(char *, size_t, char const *); size_t fmt_ulong(char *, unsigned long); diff --git a/forkexec.c b/forkexec.c @@ -3,6 +3,7 @@ #include <sys/wait.h> #include "forkexec.h" +#include "fs.h" int forkexec_wait(char *const argv[]) @@ -18,7 +19,29 @@ forkexec_wait(char *const argv[]) exit(127); } if (waitpid(pid, &st, 0) == -1) return -1; - + + return WEXITSTATUS(st); +} + +int +forkexec_wait_redir(char *const argv[], char const *path) +{ + pid_t pid = 0; + int st; + + switch ((pid = fork())) { + case -1: + return -1; + case 0: + if (dup2(1, 0) == -1) exit(125); + dprintf(1, "%s ", path); + if (!fs_redir_write(0, path)) exit(126); + execvp(*argv, argv); + exit(127); + } + + if (waitpid(pid, &st, 0) == -1) return -1; + return WEXITSTATUS(st); } diff --git a/forkexec.h b/forkexec.h @@ -1,6 +1,7 @@ #ifndef FORKEXEC_H #define FORKEXEC_H -int forkexec_wait(char *const *); +int forkexec_wait(char *const argv[]); +int forkexec_wait_redir(char *const argv[], char const *); #endif diff --git a/fs.c b/fs.c @@ -10,7 +10,7 @@ #include "stralloc.h" int -fs_isdir(char *path) +fs_isdir(char const *path) { struct stat st; if (stat(path, &st) == -1) return 0; @@ -18,7 +18,7 @@ fs_isdir(char *path) } int -fs_islink(char *path) +fs_islink(char const *path) { struct stat st; if (stat(path, &st) == -1) return 0; @@ -26,7 +26,7 @@ fs_islink(char *path) } int -fs_isfile(char *path) +fs_isfile(char const *path) { struct stat st; if (stat(path, &st) == -1) return 0; @@ -34,7 +34,34 @@ fs_isfile(char *path) } int -fs_mkdirr(char *dir, unsigned int mode) +fs_redir_read(int fd, char const *path) +{ + int newfd = open_read(path); + if (newfd == -1) return 0; + if (dup2(fd, newfd) == -1) return 0; + return 1; +} + +int +fs_redir_write(int fd, char const *path) +{ + int newfd = open_write(path); + if (newfd == -1) return 0; + if (dup2(fd, newfd) == -1) return 0; + return 1; +} + +int +fs_redir_append(int fd, char const *path) +{ + int newfd = open_append(path); + if (newfd == -1) return 0; + if (dup2(fd, newfd) == -1) return 0; + return 1; +} + +int +fs_mkdir_r(char *dir, unsigned int mode) { char *d = dir + (*dir == '/'); size_t n = 0; @@ -72,7 +99,7 @@ err: close(fd_from); } static int -fs_rmdirr_recurse(stralloc *path) +fs_remove_r_recurse(stralloc *path) { DIR *dp; struct dirent *de; @@ -95,7 +122,7 @@ fs_rmdirr_recurse(stralloc *path) if (lstat(path->x, &st) == -1) break; if (S_ISDIR(st.st_mode)) { - if (!fs_rmdirr_recurse(path)) break; + if (!fs_remove_r_recurse(path)) break; if (rmdir(path->x) == -1) break; } else { if (unlink(path->x) == -1) break; @@ -107,20 +134,20 @@ fs_rmdirr_recurse(stralloc *path) } int -fs_rmdirr(char const *dir) +fs_remove_r(char const *dir) { stralloc path = STRALLOC_ZERO; int ret = 0; if (!stralloc_cats(&path, dir)) goto err; - ret = fs_rmdirr_recurse(&path); + ret = fs_remove_r_recurse(&path); err: stralloc_free(&path); return ret; } static int -fs_copyr_recurse(stralloc *from, stralloc *to, int action) +fs_copy_r_recurse(stralloc *from, stralloc *to, int action) { DIR *dp; struct dirent *de; @@ -152,7 +179,7 @@ fs_copyr_recurse(stralloc *from, stralloc *to, int action) if (S_ISDIR(st.st_mode)) { if (mkdir(to->x, st.st_mode) == -1 && errno != EEXIST) break; - if (!fs_copyr_recurse(from, to, action)) break; + if (!fs_copy_r_recurse(from, to, action)) break; } else if (S_ISREG(st.st_mode)) { switch (action) { case 0: @@ -173,7 +200,7 @@ end: } int -fs_copyr(char const *from, char const *to) +fs_copy_r(char const *from, char const *to) { stralloc sa_from = STRALLOC_ZERO; stralloc sa_to = STRALLOC_ZERO; @@ -181,7 +208,7 @@ fs_copyr(char const *from, char const *to) if (!stralloc_cats(&sa_from, from)) goto err; if (!stralloc_cats(&sa_to, to)) goto err; - ret = fs_copyr_recurse(&sa_from, &sa_to, 0); + ret = fs_copy_r_recurse(&sa_from, &sa_to, 0); err: stralloc_free(&sa_from); stralloc_free(&sa_to); @@ -189,7 +216,7 @@ err: stralloc_free(&sa_from); } int -fs_copyrl(char const *from, char const *to) +fs_copy_rl(char const *from, char const *to) { stralloc sa_from = STRALLOC_ZERO; stralloc sa_to = STRALLOC_ZERO; @@ -197,7 +224,7 @@ fs_copyrl(char const *from, char const *to) if (!stralloc_cats(&sa_from, from)) goto err; if (!stralloc_cats(&sa_to, to)) goto err; - ret = fs_copyr_recurse(&sa_from, &sa_to, 1); + ret = fs_copy_r_recurse(&sa_from, &sa_to, 1); err: stralloc_free(&sa_from); stralloc_free(&sa_to); diff --git a/fs.h b/fs.h @@ -2,12 +2,15 @@ #define FS_H int fs_copy(char const *, char const *, unsigned int); -int fs_copyr(char const *, char const *); -int fs_copyrl(char const *, char const *); -int fs_isdir(char *); -int fs_isfile(char *); -int fs_islink(char *); -int fs_mkdirr(char *, unsigned int); -int fs_rmdirr(char const *); +int fs_copy_r(char const *, char const *); +int fs_copy_rl(char const *, char const *); +int fs_isdir(char const *); +int fs_isfile(char const *); +int fs_islink(char const *); +int fs_mkdir_r(char *, unsigned int); +int fs_redir_append(int, char const *); +int fs_redir_read(int, char const *); +int fs_redir_write(int, char const *); +int fs_remove_r(char const *); #endif diff --git a/pack-add.c b/pack-add.c @@ -1,6 +1,152 @@ +#include <sys/stat.h> +#include <errno.h> +#include <unistd.h> +#include <errno.h> + +#include "buffer.h" +#include "env.h" +#include "forkexec.h" +#include "fs.h" +#include "genalloc.h" +#include "log.h" #include "pack.h" +#include "str.h" +#include "fmt.h" + +#define nl() write(2, "\n", 1) + +void +die_nomem(void) +{ + log_diesys1(100, "malloc"); +} + +void +die_rm(char *path, pack *p) +{ + stralloc sa; + + stralloc_init(&sa); + if (!stralloc_cats(&sa, path)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, path)) goto err; + if (!stralloc_cats(&sa, "/")) goto err; + if (!stralloc_cats(&sa, p->name)) goto err; + if (!stralloc_0(&sa)) goto err; + if (!fs_remove_r(sa.x) && errno != ENOTDIR && errno != ENOENT) goto err; + exit(100); + +err: log_diesys6(100, "could not delete ", path, "/", p->name, "/", p->ver); +} + +int +step(pack *p, char *step, char *log) +{ + char fmt[PACK_FMT]; + char *argv[] = { NULL, NULL, NULL }; + stralloc sa; + int x; + int ret = 0; + + buffer_puts(buffer_2, " "); + buffer_puts(buffer_2, step + (str_start(step, "pack-") ? 5 : 0)); + buffer_puts(buffer_2, " "); + buffer_flush(buffer_2); + + stralloc_init(&sa); + if (!stralloc_cats(&sa, log)) { nl(); goto err; } + if (!stralloc_cats(&sa, "/")) { nl(); goto err; } + if (!stralloc_cats(&sa, p->name)) { nl(); goto err; } + if (!stralloc_cats(&sa, "/")) { nl(); goto err; } + if (!stralloc_cats(&sa, p->ver)) { nl(); goto err; } + if (!stralloc_0(&sa)) { nl(); goto err; } + if (!fs_mkdir_r(sa.x, 0640)) { nl(); goto err; } + if (!stralloc_cats(&sa, "/")) { nl(); goto err; } + if (!stralloc_cats(&sa, step)) { nl(); goto err; } + if (!stralloc_0(&sa)) { nl(); goto err; } + + argv[0] = step; + pack_fmt(p, fmt); + argv[1] = fmt; + x = forkexec_wait_redir(argv, sa.x); + if (x != 0) { + char fmt[4]; + fmt_long(fmt, x); + buffer_puts(buffer_2, "< exit "); + buffer_puts(buffer_2, fmt); + buffer_flush(buffer_2); + return 0; + } + ret = 1; + +err: stralloc_free(&sa); + + return ret; +} int -main(int argc, char *argv) +main(int argc, char **argv) { + (void)argc; + (void)argv; + char *def; + char *log; + char *tar; + char *src; + char *out; + genalloc ga; + stralloc sa; + size_t i; + pack p; + + if (argc != 2) log_usage(*argv, "package[/version]"); + ++argv; + + def = env_get("PACK_DEF"); if (!def) def = PACK_DEF; + log = env_get("PACK_LOG"); if (!log) log = PACK_LOG; + tar = env_get("PACK_TAR"); if (!tar) tar = PACK_TAR; + src = env_get("PACK_SRC"); if (!src) src = PACK_SRC; + out = env_get("PACK_OUT"); if (!out) out = PACK_OUT; + + if (!fs_isdir(def)) log_diesys1(101, def); + + i = pack_scan(&p, *argv); + if (i == 0 || (*argv)[i] != '\0') + log_die2(1, "invalid package name: ", *argv); + + if (!pack_version(&p, def)) + log_diesys3(101, "could not get ", *argv," version"); + + genalloc_init(&ga); + if (!pack_dep(&p, &ga, def)) + log_diesys1(103, "could not resolve package dependencies"); + if (!genalloc_append(&ga, p)) die_nomem(); + + stralloc_init(&sa); + if (!stralloc_cats(&sa, log)) die_nomem(); + if (!stralloc_cats(&sa, "/")) die_nomem(); + for (i = 0; i < genalloc_len(&ga, pack); ++i) { + pack *p = genalloc_get(&ga, pack, i); + char fmt[PACK_FMT + 80]; + + 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, " "); + buffer_flush(buffer_2); + + if (!step(p, "pack-get", log)) nl(),die_rm(tar, p); + if (!step(p, "pack-tar", log)) nl(),die_rm(src, p); + if (!step(p, "pack-build", log)) nl(),die_rm(out, p); + if (!step(p, "pack-install", log)) nl(),log_die4(100, "could not install ", p->name, "/", p->ver); + nl(); buffer_flush(buffer_2); + } + buffer_flush(buffer_1); + + genalloc_free(&ga); + + return 0; } diff --git a/pack-build.c b/pack-build.c @@ -96,14 +96,14 @@ pack_data(pack const *p, char const *def) if (!stralloc_cats(&sa, "default/data")) goto err; if (!stralloc_0(&sa)) goto err; - if (fs_isdir(sa.x)) if (!fs_copyr(sa.x, ".")) goto err; + if (fs_isdir(sa.x)) if (!fs_copy_r(sa.x, ".")) goto err; sa.n = n; if (!stralloc_cats(&sa, p->ver)) goto err; if (!stralloc_cats(&sa, "/data")) goto err; if (!stralloc_0(&sa)) goto err; - if (fs_isdir(sa.x)) if (!fs_copyr(sa.x, ".")) goto err; + if (fs_isdir(sa.x)) if (!fs_copy_r(sa.x, ".")) goto err; ret = 1; @@ -211,8 +211,7 @@ pack_patch(pack const *p, char *def) path.n = m; if (!stralloc_cats(&path, de->d_name)) goto err; if (!stralloc_0(&path)) goto err; - fd = open_read(path.x); if (fd == -1) goto err; - if (dup2(fd, 0) == -1) goto err; + if (fs_redir_read(0, path.x) == -1) goto err; if (forkexec_wait(argv) != 0) goto err; close(fd); } diff --git a/pack-dep.c b/pack-dep.c @@ -2,66 +2,13 @@ #include <errno.h> #include <unistd.h> -#include "genalloc.h" +#include "buffer.h" #include "env.h" +#include "fs.h" +#include "genalloc.h" #include "log.h" #include "pack.h" #include "str.h" -#include "buffer.h" - -static int -pack_hasdep(pack const *p, genalloc *packs) -{ - size_t i; - - for (i = 0; i < genalloc_len(packs, pack); ++i) { - pack *x = genalloc_get(packs, pack, i); - if (str_equal(x->name, p->name)) - if (str_equal(x->ver, p->ver)) - return 1; - } - - return 0; -} - -static int -pack_dep(pack const *p, genalloc *packs, char const *def) -{ - stralloc path = STRALLOC_ZERO; - stralloc line = STRALLOC_ZERO; - buffer b; - char buf[1024]; - ssize_t r; - int fd = -1; - int ret = 0; - - errno = 0; - fd = pack_opendepfile(p, def); - if (fd == -1) return (errno == ENOTDIR || errno == ENOENT); - - buffer_init(&b, &read, fd, buf, sizeof buf); - stralloc_init(&line); - while (stralloc_zero(&line), (r = buffer_getline(&b, &line))) { - pack new; - size_t n; - - stralloc_0(&line); - n = pack_scan(&new, line.x); if (n == 0) goto err; - if (line.x[n] != '\n' && line.x[n] != '\0') goto err; - if (!pack_version(&new, def)) goto err; - - if (pack_hasdep(&new, packs)) continue; - if (!pack_dep(&new, packs, def)) goto err; - if (!genalloc_append(packs, new)) goto err; - } - - ret = (r == 0); - -err: stralloc_free(&line); - stralloc_free(&path); - close(fd); - return ret; -} int main(int argc, char **argv) @@ -69,8 +16,7 @@ main(int argc, char **argv) (void)argc; (void)argv; char *def; - struct stat st; - genalloc packs; + genalloc ga; size_t i; size_t n; pack p; @@ -80,10 +26,7 @@ main(int argc, char **argv) def = env_get("PACK_DEF"); if (!def) def = PACK_DEF; - if (stat(def, &st) == -1) log_diesys1(101, def); - if (!S_ISDIR(st.st_mode)) { errno = ENOTDIR; log_diesys1(101, def); } - - genalloc_init(&packs); + if (!fs_isdir(def)) log_diesys1(101, def); n = pack_scan(&p, *argv); if (n == 0 || (*argv)[n] != '\0') @@ -92,15 +35,14 @@ main(int argc, char **argv) if (!pack_version(&p, def)) log_diesys3(103, "could not get ", *argv," version"); - if (!pack_dep(&p, &packs, def)) + genalloc_init(&ga); + if (!pack_dep(&p, &ga, def)) log_diesys1(103, "could not resolve package dependencies"); + if (!genalloc_append(&ga, p)) log_diesys1(103, "malloc"); - if (!genalloc_append(&packs, p)) - log_diesys1(103, "malloc"); - - for (i = 0; i < genalloc_len(&packs, pack); ++i) { + for (i = 0; i < genalloc_len(&ga, pack); ++i) { char fmt[PACK_FMT]; - pack *p = genalloc_get(&packs, pack, i); + pack *p = genalloc_get(&ga, pack, i); pack_fmt(p, fmt); buffer_puts(buffer_1, fmt); @@ -108,5 +50,7 @@ main(int argc, char **argv) } buffer_flush(buffer_1); + genalloc_free(&ga); + return 0; } diff --git a/pack.c b/pack.c @@ -14,12 +14,14 @@ size_t pack_fmt(pack const *p, char *buf) { - size_t i; + size_t i = 0; - i = str_copy(buf, p->name, PACK_FMT); + i += str_copy(buf + i, p->name, PACK_FMT - i); if (p->ver[0] == '\0') return i; - i += str_copy(buf + i, "/", PACK_FMT); - i += str_copy(buf + i, p->ver, PACK_FMT); + buf[i++] = '/'; + i += str_copy(buf + i, p->ver, PACK_FMT - i); + buf[i++] = '\0'; + return 1; return i; } @@ -136,8 +138,62 @@ pack_remove(pack *p, char const *prefix) if (!stralloc_cats(&path, p->ver)) goto err; if (!stralloc_append(&path, '\0')) goto err; - ret = fs_rmdirr(path.x); + ret = fs_remove_r(path.x); err: stralloc_free(&path); return ret; } + +int +pack_hasdep(pack const *p, genalloc *packs) +{ + size_t i; + + for (i = 0; i < genalloc_len(packs, pack); ++i) { + pack *x = genalloc_get(packs, pack, i); + if (str_equal(x->name, p->name)) + if (str_equal(x->ver, p->ver)) + return 1; + } + + return 0; +} + +int +pack_dep(pack const *p, genalloc *packs, char const *def) +{ + stralloc path = STRALLOC_ZERO; + stralloc line = STRALLOC_ZERO; + buffer b; + char buf[1024]; + ssize_t r; + int fd = -1; + int ret = 0; + + errno = 0; + fd = pack_opendepfile(p, def); + if (fd == -1) return (errno == ENOTDIR || errno == ENOENT); + + buffer_init(&b, &read, fd, buf, sizeof buf); + stralloc_init(&line); + while (stralloc_zero(&line), (r = buffer_getline(&b, &line))) { + pack new; + size_t n; + + stralloc_0(&line); + n = pack_scan(&new, line.x); if (n == 0) goto err; + if (line.x[n] != '\n' && line.x[n] != '\0') goto err; + if (!pack_version(&new, def)) goto err; + + if (pack_hasdep(&new, packs)) continue; + if (!pack_dep(&new, packs, def)) goto err; + if (!genalloc_append(packs, new)) goto err; + } + + ret = (r == 0); + +err: stralloc_free(&line); + stralloc_free(&path); + close(fd); + return ret; +} diff --git a/pack.h b/pack.h @@ -8,6 +8,7 @@ #define PACK_SRC "/var/pack/src" #define PACK_LOG "/var/log/pack" #define PACK_OUT "/var/pack/pkg" +#define PACK_TAR "/var/pack/tar" #define PACK_FMT (NAME_MAX * 2 + 1) @@ -16,6 +17,8 @@ typedef struct { char ver[NAME_MAX]; } pack; +int pack_dep(pack const *, genalloc *, char const *); +int pack_hasdep(pack const *, genalloc *); int pack_opendepfile(pack const *, char const *); int pack_remove(pack *, char const *); int pack_version(pack *, char const *); diff --git a/str.c b/str.c @@ -4,12 +4,12 @@ size_t str_chr(char const *buf, char c) { char *s = strchr(buf, c); - return s ? buf - s : strlen(buf); + return s ? s - buf : strlen(buf); } size_t str_rchr(char const *buf, char c) { char *s = strrchr(buf, c); - return s ? buf - s : strlen(buf); + return s ? s - buf : strlen(buf); } diff --git a/str.h b/str.h @@ -10,7 +10,7 @@ #define str_equal(buf1, buf2) (!strcmp(buf1, buf2)) #define str_equaln(buf1, buf2, n) (!strncmp(buf1, buf2, n)) #define str_len(buf) strlen(buf) -#define str_start(buf1, buf2) (!strncmp(buf1, buf2, strlen(buf1))) +#define str_start(buf1, buf2) (!strncmp(buf1, buf2, strlen(buf2))) size_t str_chr(char const *, char); size_t str_rchr(char const *, char);