Working as of 12/11
This commit is contained in:
1 parent
e591b71143
commit
e79c96a987
29 files changed
+664
-48
No files matched your search
@@ -3,12 +3,14 @@
|
||||
|
||||
#include <errno.h>
|
||||
#include <libconfig.h>
|
||||
#include <limits.h>
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <sys/stat.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "common.h"
|
||||
|
||||
@@ -80,6 +82,24 @@ static const dir_t gl_sys_store = { "/glacier/sys/store", 0700 };
|
||||
static dep_t null_dep = { "null", {-1, -1, -1, NULL} };
|
||||
static conf_t null_conf = { "null", {-1, -1, -1, NULL} };
|
||||
|
||||
static char
|
||||
*join_with_cwd(const char *path)
|
||||
{
|
||||
char cwd[PATH_MAX];
|
||||
|
||||
if (!getcwd(cwd, sizeof(cwd))) {
|
||||
perror("getcwd");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size_t length = strlen(cwd + strlen(path) + 2);
|
||||
char *result = malloc(length);
|
||||
if (!result) { return NULL; }
|
||||
|
||||
snprintf(result, length, "%s/%s", cwd, path);
|
||||
return result;
|
||||
}
|
||||
|
||||
/*
|
||||
* gl_pkgver
|
||||
* DESCRIPTION: takes three integers and formats them as a semver_t struct
|
||||
@@ -119,7 +139,7 @@ gl_parse_semver(const char *str)
|
||||
}
|
||||
|
||||
void
|
||||
gl_free_semver(semver_T *v)
|
||||
gl_free_semver(semver_t *v)
|
||||
{
|
||||
if (v && v->tag) { free (v->tag); };
|
||||
}
|
||||
@@ -164,7 +184,7 @@ gl_pkg_t
|
||||
}
|
||||
|
||||
int
|
||||
gl_gpm2pkg(const char *filename, gl_pkg_t *pkg)
|
||||
gl_gpm2gpkg(const char *filename, gl_pkg_t *pkg)
|
||||
{
|
||||
config_t cfg;
|
||||
config_setting_t *deps, *confs;
|
||||
@@ -179,7 +199,7 @@ gl_gpm2pkg(const char *filename, gl_pkg_t *pkg)
|
||||
if (config_lookup_string(&cfg, "PKG_NAME", &tmp_str)) { pkg->pkg_name = strdup(tmp_str); }
|
||||
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 = strup(tmp_str); }
|
||||
if (config_lookup_string(&cfg, "PKG_COPYRIGHT", &tmp_str)) { pkg->pkg_copyright = 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");
|
||||
@@ -196,7 +216,7 @@ gl_gpm2pkg(const char *filename, gl_pkg_t *pkg)
|
||||
config_setting_lookup_string(d, "PKG_VER", &dep_ver);
|
||||
|
||||
pkg->pkg_dependencies[i].dep_name = dep_name ? strdup(dep_name) : NULL;
|
||||
pkg->pkg_dependencies[i].dep_ver = parse_semver(dep_ver);
|
||||
pkg->pkg_dependencies[i].dep_ver = gl_parse_semver(dep_ver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -214,7 +234,7 @@ gl_gpm2pkg(const char *filename, gl_pkg_t *pkg)
|
||||
config_setting_lookup_string(c, "PKG_VER", &conf_ver);
|
||||
|
||||
pkg->pkg_conflicts[i].conf_name = conf_name ? strdup(conf_name) : NULL;
|
||||
pkg->pkg_conflicts[i].conf_ver = parse_semver(conf_ver);
|
||||
pkg->pkg_conflicts[i].conf_ver = gl_parse_semver(conf_ver);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -280,6 +300,35 @@ gl_free_dir(dir_t *dir)
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
gl_free_pkg(gl_pkg_t *pkg)
|
||||
{
|
||||
if (!pkg) return;
|
||||
|
||||
free(pkg->pkg_name);
|
||||
free(pkg->pkg_desc);
|
||||
free(pkg->pkg_maint);
|
||||
free(pkg->pkg_copyright);
|
||||
|
||||
gl_free_semver(&pkg->pkg_ver);
|
||||
|
||||
if (pkg->pkg_dependencies) {
|
||||
for (dep_t *d = pkg->pkg_dependencies; d->dep_name; d++) {
|
||||
free(d->dep_name);
|
||||
gl_free_semver(&d->dep_ver);
|
||||
}
|
||||
free(pkg->pkg_dependencies);
|
||||
}
|
||||
|
||||
if (pkg->pkg_conflicts) {
|
||||
for (conf_t *c = pkg->pkg_conflicts; c->conf_name; c++) {
|
||||
free(c->conf_name);
|
||||
gl_free_semver(&c->conf_ver);
|
||||
}
|
||||
free(pkg->pkg_conflicts);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
gl_prepare_pkgdir(gl_pkg_t *pkg, bool is_syspkg)
|
||||
{
|
||||
@@ -364,6 +413,16 @@ main(void)
|
||||
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;
|
||||
@@ -371,4 +430,7 @@ main(void)
|
||||
else {
|
||||
return 1;
|
||||
}
|
||||
|
||||
gl_free_pkg(foo);
|
||||
gl_free_pkg(&bar);
|
||||
}
|
||||
Reference in new issue
Block a user