nkiss

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

commit 64043edbfce464f0d829896ed94a75b9542ef1de
parent 94f5d599d18442fe4f4339e93b38a0bdd83ac87e
Author: Nihal Jere <nihal@nihaljere.xyz>
Date:   Thu, 18 Feb 2021 16:25:09 -0600

pkg.*: add pkg_sources which loads source information for a package

Diffstat:
Mpkg.c | 56++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpkg.h | 9+++++++++
2 files changed, 65 insertions(+), 0 deletions(-)

diff --git a/pkg.c b/pkg.c @@ -8,6 +8,62 @@ #include "pkg.h" #include "util.h" +int pkg_sources(char *repo, char *name, struct source_t *sources) +{ + FILE *sfile; + char path[strlen(repo) + strlen(name) + 10]; + char line[512], *p, *end; + int i = 0; + + strcpy(path, repo); + strcat(path, "/"); + strcat(path, name); + strcat(path, "/sources"); + + if ((sfile = fopen(path, "r")) == NULL) + die("%s: failed to open sources file for %s:", __func__, name); + + while (fgets(line, 512, sfile)) { + p = line; + + if (strncmp(p, "git+", sizeof("git+") - 1) == 0) { + sources[i].git = 1; + p += sizeof("git+") - 1; + } + + /* we are given an extraction path */ + if ((end = strchr(p, ' '))) { + strncpy(sources[i].url, p, end - p); + sources[i].url[end - p] = '\0'; + + /* no NULL check needed, as we know its in the string */ + p = strrchr(p, ' ') + 1; + end = strrchr(p, '\n'); + strncpy(sources[i].path, p, end - p); + sources[i].path[end - p] = '\0'; + } else { + end = strchr(p, '\n'); + strncpy(sources[i].url, p, end-p); + sources[i].url[end-p] = '\0'; + } + + if (++i > PKG_SOURCES_MAX) { + fclose(sfile); + die("%s: too many sources for %s", __func__, name); + } + + } + + if (ferror(sfile)) { + fclose(sfile); + die("%s: error when reading sources for %s", __func__, name); + } + + fclose(sfile); + + return i; +} + void pkg_version(char *repo, char *name, char *ver) { diff --git a/pkg.h b/pkg.h @@ -1,9 +1,18 @@ #define KISS_INSTALLED "/var/db/kiss/installed" #define PKG_VERSION_MAX 256 +#define PKG_SOURCES_MAX 64 #define PKG_COUNT_MAX 1024 #define PKG_NAME_MAX 64 #define PATH_LEN 512 +#define URL_LEN 2048 +struct source_t { + char git; + char url[URL_LEN]; + char path[PATH_LEN]; +}; + +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); int pkg_exists(const char *repo, const char *name, char *path);