nkiss

WIP
git clone git://git.nihaljere.xyz/nkiss
Log | Files | Refs

commit a6d417232fac62843657d7106e289af252fd31ca
parent 5d25a0fd1632f4ffc6804b4f079258f15f4242fa
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Sat, 20 Feb 2021 22:30:13 -0600

pkg.*: add pkg_checksums_gen

Generates checksums file

Diffstat:
Mpkg.c | 24++++++++++++++++++++++++
Mpkg.h | 1+
2 files changed, 25 insertions(+), 0 deletions(-)

diff --git a/pkg.c b/pkg.c @@ -142,6 +142,30 @@ void pkg_checksums_load(char *repo, char *name, struct source_t *sources) { } void +pkg_checksums_gen(char *repo, char *name, struct source_t *sources) +{ + char cpath[PATH_LEN], hash[HASH_LEN], hashstr[HASH_LEN*2+1]; + FILE *cfile; + + if (snprintf(cpath, PATH_LEN, "%s/%s/checksums", repo, name) > PATH_LEN) + die("%s: path %s too long", __func__, cpath); + + if ((cfile = fopen(cpath, "w")) == NULL) + die("%s: failed to open checksums file for %s:", __func__, name); + + for (int i = 0; sources[i].path[0] != '\0'; i++) { + if (sha256_file(sources[i].path, hash) < 0) { + fclose(cfile); + die("%s: failed to hash %s", __func__, sources[i].path); + } + sha256_tostr(hashstr, hash); + fprintf(cfile, "%s\n", hashstr); + } + + fclose(cfile); +} + +void pkg_version(char *repo, char *name, char *ver) { char path[PATH_LEN]; diff --git a/pkg.h b/pkg.h @@ -20,6 +20,7 @@ struct source_t { void pkg_retrieve(struct source_t *sources, int count); int pkg_sources(char *repo, char *name, struct source_t *); void pkg_checksums_load(char *repo, char *name, struct source_t *); +void pkg_checksums_gen(char *repo, char *name, struct source_t *sources); void pkg_version(char *repo, char *name, char *ver); void pkg_binpath(char *repo, char *name, char *binpath); int pkg_match(char *repo, char pkgs[][64], const char *pattern);