nkiss

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

commit 60619769b5c4274263cfd316226464735f2b2bd8
parent df6050eddd126f55dc9f3c3567cc12f7763daec8
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 18 Feb 2021 21:13:24 -0600

changed pkg_download's function

pkg_download now just downloads a list of sources
kiss_download_names calls pkg_sources, and does related memory
management

Diffstat:
Mkiss.c | 27++++++++++++++++-----------
Mpkg.c | 10++++------
Mpkg.h | 2+-
3 files changed, 21 insertions(+), 18 deletions(-)

diff --git a/kiss.c b/kiss.c @@ -14,22 +14,27 @@ char *argv0; void kiss_download_names(char *kiss_path, char *names[], int len) { - char *repo, path[strlen(kiss_path)]; + struct source_t sources[PKG_SOURCES_MAX]; + memset(sources, 0, sizeof(sources)); + char *repo, kp[strlen(kiss_path)], path[PATH_LEN]; + int count; - memccpy(path, kiss_path, '\0', strlen(kiss_path)); + /* TODO put names in linked list to make O(n) instead of O(n^2) */ + for (int i = 0; i < len; i++) { + /* iterate through KISS_PATH */ + memccpy(kp, kiss_path, '\0', strlen(kiss_path)); - if ((repo = strtok(path, ":")) == NULL) - die("Invalid KISS_PATH."); + if ((repo = strtok(kp, ":")) == NULL) + die("Invalid KISS_PATH."); - /* iterate through KISS_PATH */ - do { - path[0] = '\0'; - for (int i = 0; i < len; i++) { + do { if (pkg_exists(repo, names[i], path)) { - pkg_download(repo, names[i]); + count = pkg_sources(repo, names[i], sources); + pkg_download(names[i], sources, count); + break; } - } - } while ((repo = strtok(NULL, ":")) != NULL); + } while ((repo = strtok(NULL, ":")) != NULL); + } } void diff --git a/pkg.c b/pkg.c @@ -12,25 +12,23 @@ #include "util.h" void -pkg_download(char *repo, char *name) +pkg_download(char *name, struct source_t *sources, int count) { - struct source_t sources[PKG_SOURCES_MAX]; char destpath[PATH_LEN]; - size_t dirlen = 0, sourcecount; + size_t dirlen = 0; - sourcecount = pkg_sources(repo, name, sources); get_cache_dir(destpath); strcat(destpath, "/sources/"); dirlen = strlen(destpath); - for (int i = 0; i < sourcecount; i++) { + for (int i = 0; i < count; i++) { destpath[dirlen] = '\0'; strcat(destpath, name); strcat(destpath, "/"); mkdirs(destpath); strcat(destpath, basename(sources[i].loc)); - if (access(destpath, F_OK)) + if (access(destpath, F_OK) && !sources[i].local) http_fetch(sources[i].loc, destpath); } } diff --git a/pkg.h b/pkg.h @@ -13,7 +13,7 @@ struct source_t { char path[PATH_LEN]; }; -void pkg_download(char *repo, char *name); +void pkg_download(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);