nkiss

Unnamed repository; edit this file 'description' to name the repository.
git clone git://git.nihaljere.xyz/nkiss
Log | Files | Refs

commit 90d9b38b296c350ce27091f2cf8c5ccade02c3cc
parent 81ec83e8de748a975958f3a5e6c8b3eeea90fc82
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 18 Feb 2021 18:36:31 -0600

pkg.*: add pkg_download

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

diff --git a/pkg.c b/pkg.c @@ -1,13 +1,37 @@ #include <dirent.h> #include <errno.h> #include <fnmatch.h> +#include <libgen.h> #include <stdlib.h> #include <stdio.h> #include <string.h> +#include "http.h" #include "pkg.h" #include "util.h" +void +pkg_download(char *repo, char *name) +{ + struct source_t sources[PKG_SOURCES_MAX]; + char destpath[PATH_LEN]; + size_t dirlen = 0, sourcecount; + + sourcecount = pkg_sources(repo, name, sources); + get_cache_dir(destpath); + strcat(destpath, "/sources/"); + dirlen = strlen(destpath); + + for (int i = 0; i < sourcecount; i++) { + destpath[dirlen] = '\0'; + strcat(destpath, name); + strcat(destpath, "/"); + mkdirs(destpath); + strcat(destpath, basename(sources[i].url)); + http_fetch(sources[i].url, destpath); + } +} + int pkg_sources(char *repo, char *name, struct source_t *sources) { FILE *sfile; diff --git a/pkg.h b/pkg.h @@ -12,6 +12,7 @@ struct source_t { char path[PATH_LEN]; }; +void pkg_download(char *repo, char *name); int pkg_sources(char *repo, char *name, struct source_t *); void pkg_version(char *repo, char *name, char *ver); int pkg_match(char *repo, char pkgs[][64], const char *pattern);