nkiss

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

commit e3a6a4cdd06f42a55c808bc6007f3b935f03188e
parent ef98fb3a34095703f342f5170146843081470729
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 18 Feb 2021 22:28:48 -0600

pkg.*: replace pkg_download with pkg_retrieve

pkg_retrieve verifies the existence of local sources as well as download
uncached remote sources

Diffstat:
Mkiss.c | 2+-
Mpkg.c | 51+++++++++++++++++++++++++++++++++------------------
Mpkg.h | 2+-
3 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/kiss.c b/kiss.c @@ -30,7 +30,7 @@ kiss_download_names(char *kiss_path, char *names[], int len) do { if (pkg_exists(repo, names[i], path)) { count = pkg_sources(repo, names[i], sources); - pkg_download(names[i], sources, count); + pkg_retrieve(repo, names[i], sources, count); break; } } while ((repo = strtok(NULL, ":")) != NULL); diff --git a/pkg.c b/pkg.c @@ -12,29 +12,44 @@ #include "util.h" void -pkg_download(char *name, struct source_t *sources, int count) +pkg_retrieve(char *repo, char *name, struct source_t *sources, int count) { - char destpath[PATH_LEN]; - size_t dirlen = 0; + char cachepath[PATH_LEN], repopath[PATH_LEN]; + size_t clen = 0, rlen = 0; - get_cache_dir(destpath); - strcat(destpath, "/sources/"); - dirlen = strlen(destpath); + get_cache_dir(cachepath); + strcat(cachepath, "/sources/"); + clen = strlen(cachepath); + + strcpy(repopath, repo); + strcat(repopath, "/"); + strcat(repopath, name); + strcat(repopath, "/"); + rlen = strlen(repopath); for (int i = 0; i < count; i++) { - destpath[dirlen] = '\0'; - strcat(destpath, name); - strcat(destpath, "/"); - if (sources[i].path) { - strcat(destpath, sources[i].path); - strcat(destpath, "/"); - } + if (sources[i].local) { + strcat(repopath, sources[i].loc); + if (access(cachepath, F_OK)) + die("pkg_retrieve: cannot find local source %s for %s", + sources[i].loc, name); - mkdirs(destpath); - strcat(destpath, basename(sources[i].loc)); - - if (access(destpath, F_OK) && !sources[i].local) - http_fetch(sources[i].loc, destpath); + repopath[rlen] = '\0'; + } else { + strcat(cachepath, name); + strcat(cachepath, "/"); + if (sources[i].path) { + strcat(cachepath, sources[i].path); + strcat(cachepath, "/"); + } + + mkdirs(cachepath); + strcat(cachepath, basename(sources[i].loc)); + + if (access(cachepath, F_OK)) + http_fetch(sources[i].loc, cachepath); + cachepath[clen] = '\0'; + } } } diff --git a/pkg.h b/pkg.h @@ -13,7 +13,7 @@ struct source_t { char path[PATH_LEN]; }; -void pkg_download(char *name, struct source_t *sources, int count); +void pkg_retrieve(char *repo, char *name, struct source_t *sources, int count); 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);