3/18: Functional package installation backend
This commit is contained in:
1 parent
e79c96a987
commit
6819fe7c69
24 files changed
+1011
-145
No files matched your search
@@ -13,76 +13,24 @@
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
/*
|
||||
* semver_t
|
||||
* DESCRIPTION: defines the struct for storing semantic versioning numbers
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
int maj;
|
||||
int min;
|
||||
int pat;
|
||||
char *tag;
|
||||
}
|
||||
semver_t;
|
||||
|
||||
/*
|
||||
* dep_t
|
||||
* DESCRIPTION: defines the struct for storing dependent packages
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *dep_name;
|
||||
semver_t dep_ver;
|
||||
}
|
||||
dep_t;
|
||||
|
||||
/*
|
||||
* conf_t
|
||||
* DESCRIPTION: defines the struct for storing conflicting packages
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *conf_name;
|
||||
semver_t conf_ver;
|
||||
}
|
||||
conf_t;
|
||||
|
||||
/*
|
||||
* gl_pkg_t
|
||||
* DESCRIPTION: defines the struct for storing packages in the gpkg format
|
||||
*/
|
||||
typedef struct
|
||||
{
|
||||
char *pkg_name;
|
||||
semver_t pkg_ver;
|
||||
|
||||
char *pkg_desc;
|
||||
char *pkg_maint;
|
||||
char *pkg_copyright;
|
||||
|
||||
dep_t *pkg_dependencies;
|
||||
conf_t *pkg_conflicts;
|
||||
}
|
||||
gl_pkg_t;
|
||||
#include "pkg.h"
|
||||
|
||||
/* directory definitions */
|
||||
static const dir_t gl_root = { "/glacier", 0750 };
|
||||
const dir_t gl_root = { "/glacier", 0750 };
|
||||
|
||||
static const dir_t gl_usr = { "/glacier/usr", 0700 };
|
||||
static const dir_t gl_usr_index = { "/glacier/usr/index", 0700 };
|
||||
static const dir_t gl_usr_store = { "/glacier/usr/store", 0700 };
|
||||
const dir_t gl_usr = { "/glacier/usr", 0700 };
|
||||
const dir_t gl_usr_index = { "/glacier/usr/index", 0700 };
|
||||
const dir_t gl_usr_store = { "/glacier/usr/store", 0700 };
|
||||
|
||||
static const dir_t gl_sys = { "/glacier/sys", 0700 };
|
||||
static const dir_t gl_sys_index = { "/glacier/sys/index", 0700 };
|
||||
static const dir_t gl_sys_store = { "/glacier/sys/store", 0700 };
|
||||
const dir_t gl_sys = { "/glacier/sys", 0700 };
|
||||
const dir_t gl_sys_index = { "/glacier/sys/index", 0700 };
|
||||
const dir_t gl_sys_store = { "/glacier/sys/store", 0700 };
|
||||
|
||||
/* null dependencies/conflicts for error throwing */
|
||||
static dep_t null_dep = { "null", {-1, -1, -1, NULL} };
|
||||
static conf_t null_conf = { "null", {-1, -1, -1, NULL} };
|
||||
dep_t null_dep = { "null", {-1, -1, -1, NULL} };
|
||||
conf_t null_conf = { "null", {-1, -1, -1, NULL} };
|
||||
|
||||
static char
|
||||
char
|
||||
*join_with_cwd(const char *path)
|
||||
{
|
||||
char cwd[PATH_MAX];
|
||||
@@ -150,6 +98,7 @@ gl_pkg_t empty = {
|
||||
"Null package for internal use. Returned upon an error.",
|
||||
"null@null.null",
|
||||
"null",
|
||||
"null",
|
||||
&null_dep,
|
||||
&null_conf
|
||||
};
|
||||
@@ -167,7 +116,7 @@ gl_mkdir(dir_t *dir)
|
||||
}
|
||||
|
||||
gl_pkg_t
|
||||
*gl_spawn_pkg(char *name, semver_t *ver, char *desc, char *maint, char *copy, dep_t *dep, conf_t *conf)
|
||||
*gl_spawn_pkg(char *name, semver_t *ver, char *desc, char *maint, char *copy, char *repo, dep_t *dep, conf_t *conf)
|
||||
{
|
||||
gl_pkg_t *new_pkg = malloc(sizeof(gl_pkg_t));
|
||||
if (!new_pkg) { return NULL; }
|
||||
@@ -177,6 +126,7 @@ gl_pkg_t
|
||||
new_pkg -> pkg_desc = desc;
|
||||
new_pkg -> pkg_maint = maint;
|
||||
new_pkg -> pkg_copyright = copy;
|
||||
new_pkg -> pkg_repo = repo;
|
||||
new_pkg -> pkg_dependencies = dep;
|
||||
new_pkg -> pkg_conflicts = conf;
|
||||
|
||||
@@ -200,15 +150,16 @@ gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg)
|
||||
if (config_lookup_string(&cfg, "PKG_DESC", &tmp_str)) { pkg->pkg_desc = strdup(tmp_str); }
|
||||
if (config_lookup_string(&cfg, "PKG_MAINT", &tmp_str)) { pkg->pkg_maint = strdup(tmp_str); }
|
||||
if (config_lookup_string(&cfg, "PKG_COPYRIGHT", &tmp_str)) { pkg->pkg_copyright = strdup(tmp_str); }
|
||||
if (config_lookup_string(&cfg, "PKG_REPO", &tmp_str)) { pkg->pkg_repo = strdup(tmp_str); }
|
||||
if (config_lookup_string(&cfg, "PKG_VER", &tmp_str)) { pkg->pkg_ver = gl_parse_semver(tmp_str); }
|
||||
|
||||
deps = config_lookup(&cfg, "PKG_DEPS");
|
||||
if (deps && config_setting_is_list(deps)) {
|
||||
int count = config_setting_length(deps);
|
||||
pkg->pkg_dependencies = calloc(count + 1, sizeof(dep_t));
|
||||
pkg->pkg_dependencies = calloc((size_t)(count + 1), sizeof(dep_t));
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
config_setting_t *d = config_setting_get_elem(deps, i);
|
||||
config_setting_t *d = config_setting_get_elem(deps, (unsigned int)i);
|
||||
const char *dep_name = NULL;
|
||||
const char *dep_ver = NULL;
|
||||
|
||||
@@ -223,10 +174,10 @@ gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg)
|
||||
confs = config_lookup(&cfg, "PKG_CONFS");
|
||||
if (confs && config_setting_is_list(confs)) {
|
||||
int count = config_setting_length(confs);
|
||||
pkg->pkg_conflicts = calloc(count + 1, sizeof(conf_t));
|
||||
pkg->pkg_conflicts = calloc((size_t)(count + 1), sizeof(conf_t));
|
||||
|
||||
for (int i = 0; i < count; i++) {
|
||||
config_setting_t *c = config_setting_get_elem(confs, i);
|
||||
config_setting_t *c = config_setting_get_elem(confs, (unsigned int)i);
|
||||
const char *conf_name = NULL;
|
||||
const char *conf_ver = NULL;
|
||||
|
||||
@@ -295,7 +246,7 @@ void
|
||||
gl_free_dir(dir_t *dir)
|
||||
{
|
||||
if (dir && dir->path) {
|
||||
free(dir->path);
|
||||
free((char *)dir->path);
|
||||
dir->path = NULL;
|
||||
}
|
||||
}
|
||||
@@ -309,6 +260,7 @@ gl_free_pkg(gl_pkg_t *pkg)
|
||||
free(pkg->pkg_desc);
|
||||
free(pkg->pkg_maint);
|
||||
free(pkg->pkg_copyright);
|
||||
free(pkg->pkg_repo);
|
||||
|
||||
gl_free_semver(&pkg->pkg_ver);
|
||||
|
||||
@@ -394,43 +346,3 @@ gl_show_pkg_props(const gl_pkg_t *pkg)
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main(void)
|
||||
{
|
||||
semver_t foo_v = gl_pkgver(1, 1, 1);
|
||||
dep_t dep_empty = {"empty", foo_v};
|
||||
conf_t conf_empty = {"empty", foo_v};
|
||||
gl_pkg_t *foo = gl_spawn_pkg(
|
||||
"foo",
|
||||
&foo_v,
|
||||
"example pkg",
|
||||
"liamwaldron@everestlinux.org",
|
||||
"GPL3",
|
||||
&dep_empty,
|
||||
&conf_empty
|
||||
);
|
||||
|
||||
gl_show_pkg_props(foo);
|
||||
gl_show_pkg_props(&empty);
|
||||
|
||||
gl_pkg_t bar = {0};
|
||||
|
||||
char *bar_path = join_with_cwd("bar.gpm.cfg");
|
||||
if (!bar_path) { return 1; }
|
||||
|
||||
if (gl_gpm2gpkg(bar_path, &bar) == 0) { gl_show_pkg_props(&bar); }
|
||||
else { return 99; }
|
||||
|
||||
free(bar_path);
|
||||
|
||||
if (gl_prepare_pkgdir(foo, false) == 0) {
|
||||
printf("Package prepared\n");
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
gl_free_pkg(foo);
|
||||
gl_free_pkg(&bar);
|
||||
}
|
||||
Reference in new issue
Block a user