ckiss

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 6121d51d9f1a0458bdcdedc00ce413d2c1bd58c9
parent 6ec4de00a7557cab85281761a2f5221686a429a8
Author: phoebos <ben@bvnf.space>
Date:   Tue, 27 Jun 2023 23:05:01 +0100

bad download

Diffstat:
MREADME | 2+-
Msrc/Makefile | 3++-
Msrc/actions.h | 1+
Asrc/download.c | 55+++++++++++++++++++++++++++++++++++++++++++++++++++++++
Msrc/main.c | 4++++
5 files changed, 63 insertions(+), 2 deletions(-)

diff --git a/README b/README @@ -10,7 +10,7 @@ An implementation of the kiss package manager in C. [ ] build [ ] hooks [x] checksum -[ ] download +[.] download [ ] install [x] list [ ] remove diff --git a/src/Makefile b/src/Makefile @@ -2,7 +2,7 @@ XCFLAGS = $(CFLAGS) -Wall -Wextra -Wshadow -pedantic -D_XOPEN_SOURCE=700 -Og -g -OBJS = utils.o list.o search.o array.o checksum.o checksums.o pkg.o update.o +OBJS = utils.o list.o search.o array.o checksum.o checksums.o pkg.o update.o download.o LIBS = -lblake3 all: ckiss @@ -36,4 +36,5 @@ checksum.o: actions.h pkg.h utils.h checksums.h checksums.o: utils.h checksums.h pkg.o: pkg.h utils.h update.o: actions.h utils.h +download.o: actions.h utils.h pkg.h main.o: actions.h utils.h diff --git a/src/actions.h b/src/actions.h @@ -6,4 +6,5 @@ int list(int argc, char **argv, struct env *e); int search(int argc, char **argv, struct env *e); int checksum(int argc, char **argv, struct env *e); int update(struct env *e); +int download(int argc, char **argv, struct env *e); #endif diff --git a/src/download.c b/src/download.c @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <unistd.h> +#include "utils.h" +#include "actions.h" +#include "pkg.h" + +int +git_download(struct source *s, struct env *e) { + return 0; +} + +int +http_download(struct source *s, struct env *e) { + if (access(s->cachefile, F_OK) == 0) { + mylog2("cached", s->cachefile); + return 0; + } + /* TODO: this only works once! need to copy e->get, not modify it. */ + size_t i; + for (i = 0; i < 6; i++) { + if (e->get[i] == NULL) + break; + } + if (i > 5) die2(e->get[0], "too many args"); + e->get[i++] = s->cachefile; + e->get[i++] = s->remote; + e->get[i] = NULL; + + return run(e->get); +} + +int +download(int argc, char **argv, struct env *e) { + if (argc < 2) + die2("download", "need a package(s)"); + + for (int i = 1; i < argc; i++) { + struct pkg *p = pkg_parse_sources(argv[i], e); + for (size_t j = 0; j < p->n; j++) { + switch (p->s[j]->type) { + case SRC_GIT: + git_download(p->s[j], e); + break; + case SRC_HTTP: + http_download(p->s[j], e); + break; + case SRC_FILE: /* FALLTHROUGH */ + default: + break; + } + } + pkg_free(p); + } + return 0; +} diff --git a/src/main.c b/src/main.c @@ -10,6 +10,7 @@ noreturn void usage(int r) { mylog("ckiss [c|l|s|v] [pkg]..."); mylog("checksum Generate checksums"); + mylog("download Download sources"); mylog("list List installed packages"); mylog("search Search for packages"); mylog("update Update the repositories"); @@ -29,6 +30,9 @@ main(int argc, char **argv) { case 'c': ret = checksum(argc - 1, argv + 1, e); break; + case 'd': + ret = download(argc - 1, argv + 1, e); + break; case 'l': ret = list(argc - 1, argv + 1, e); break;