commit 23505c5e178c7197313b4a08ce61241c69bd7f9a
parent 033d81cf8e2320dfa39e7a506474d898bd60bfab
Author: Nihal Jere <nihal@nihaljere.xyz>
Date: Fri, 19 Feb 2021 19:31:42 -0600
pkg.*: add pkg_binpath
pkg_binpath determines where the package (binary) tarball is, so it can
be installed
Diffstat:
2 files changed, 26 insertions(+), 0 deletions(-)
diff --git a/pkg.c b/pkg.c
@@ -136,6 +136,31 @@ pkg_version(char *repo, char *name, char *ver)
fclose(vfile);
}
+void
+pkg_binpath(char *repo, char *name, char *binpath)
+{
+ char ver[PKG_VERSION_MAX], cachepath[PATH_LEN];
+ char *p;
+ int ret;
+
+ pkg_version(repo, name, ver);
+ if ((p = strchr(ver, ' ')) == NULL)
+ die("%s: malformatted version file", __func__);
+
+ *p = '-';
+
+ if ((p = strchr(ver, '\n')) == NULL)
+ die("%s: malformatted version file", __func__);
+
+ *p = '\0';
+ get_cache_dir(cachepath);
+ ret = snprintf(binpath, PATH_LEN, "%s/bin/%s@%s.tar.gz", cachepath, name,
+ ver);
+
+ if (ret > PATH_LEN)
+ die("%s: binpath too long", __func__);
+}
+
int
pkg_match(char *repo, char pkgs[][PKG_NAME_MAX], const char *pattern)
{
diff --git a/pkg.h b/pkg.h
@@ -16,6 +16,7 @@ struct source_t {
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);
+void pkg_binpath(char *repo, char *name, char *binpath);
int pkg_match(char *repo, char pkgs[][64], const char *pattern);
int pkg_exists(const char *repo, const char *name, char *path);
void get_cache_dir(char *path);