Radish alpha
H
HardenedBSD Package Manager
Radicle
Git (anonymous pull)
Log in to clone via SSH
WIP pkg add (missing script executions)
Baptiste Daroussin committed 15 years ago
commit ed0cae1dad1f52c9b17ef69afbb2321a3d961aab
parent 42424c573b37034a0d6e67f135e09439d931228f
4 files changed +109 -77
modified libpkg/pkg.c
@@ -239,6 +239,42 @@ pkg_open(const char *path, struct pkg **pkg, int query_flags)
	return (0);
}

+
#define EXTRACT_ARCHIVE_FLAGS  (ARCHIVE_EXTRACT_OWNER |ARCHIVE_EXTRACT_PERM| \
+
		ARCHIVE_EXTRACT_TIME  |ARCHIVE_EXTRACT_ACL | \
+
		ARCHIVE_EXTRACT_FFLAGS|ARCHIVE_EXTRACT_XATTR)
+
int
+
pkg_extract(const char *path)
+
{
+
	struct archive *a;
+
	struct archive_entry *ae;
+

+
	int ret;
+

+
	a = archive_read_new();
+
	archive_read_support_compression_all(a);
+
	archive_read_support_format_tar(a);
+

+
	if (archive_read_open_filename(a, path, 4096) != ARCHIVE_OK) {
+
		archive_read_finish(a);
+
		return (-1);
+
	}
+

+
	while ((ret = archive_read_next_header(a, &ae)) == ARCHIVE_OK) {
+
		if (archive_entry_pathname(ae)[0] == '+') {
+
			archive_read_data_skip(a);
+
		} else {
+
			archive_read_extract(a, ae, EXTRACT_ARCHIVE_FLAGS);
+
		}
+
	}
+

+
	if (ret != ARCHIVE_EOF)
+
		warn("Archive corrupted");
+

+
	archive_read_finish(a);
+

+
	return (0);
+
}
+

int
pkg_new(struct pkg **pkg)
{
@@ -413,6 +449,7 @@ pkg_adddep(struct pkg *pkg, const char *name, const char *origin, const char *ve
	pkg_set(dep, PKG_NAME, name);
	pkg_set(dep, PKG_ORIGIN, origin);
	pkg_set(dep, PKG_VERSION, version);
+
	dep->type = PKG_NOTFOUND;

	array_init(&pkg->deps, 5);
	array_append(&pkg->deps, dep);
modified libpkg/pkg.h
@@ -70,7 +70,9 @@ struct pkg_conflict ** pkg_conflicts(struct pkg *);
struct pkg_script ** pkg_scripts(struct pkg *);
struct pkg_exec ** pkg_execs(struct pkg *);
struct pkg_option ** pkg_options(struct pkg *);
+

int pkg_resolvdeps(struct pkg *, struct pkgdb *db);
+
int pkg_extract(const char *filename);

/* pkg setters */
int pkg_set(struct pkg *, pkg_attr, const char *);
modified libpkg/pkg_manifest.c
@@ -15,15 +15,13 @@ static int m_parse_name(struct pkg *pkg, char *buf);
static int m_parse_origin(struct pkg *pkg, char *buf);
static int m_parse_version(struct pkg *pkg, char *buf);
static int m_parse_arch(struct pkg *pkg, char *buf);
-
static int m_parse_osrelease(struct pkg *pkg, char *buf);
static int m_parse_osversion(struct pkg *pkg, char *buf);
-
static int m_parse_build_time(struct pkg *pkg, char *buf);
static int m_parse_www(struct pkg *pkg, char *buf);
static int m_parse_comment(struct pkg *pkg, char *buf);
-
static int m_parse_license(struct pkg *pkg, char *buf);
static int m_parse_option(struct pkg *pkg, char *buf);
static int m_parse_dep(struct pkg *pkg, char *buf);
static int m_parse_conflict(struct pkg *pkg, char *buf);
+
static int m_parse_maintainer(struct pkg *pkg, char *buf);

#define MANIFEST_FORMAT_KEY "@pkg_format_version"

@@ -35,20 +33,38 @@ static struct manifest_key {
	{ "@origin", m_parse_origin},
	{ "@version", m_parse_version},
	{ "@arch", m_parse_arch},
-
	{ "@osrelease", m_parse_osrelease},
	{ "@osversion", m_parse_osversion},
-
	{ "@build_time", m_parse_build_time},
	{ "@www", m_parse_www},
	{ "@comment", m_parse_comment},
-
	{ "@license", m_parse_license},
	{ "@option", m_parse_option},
	{ "@dep", m_parse_dep},
	{ "@conflict", m_parse_conflict},
+
	{ "@maintainer", m_parse_maintainer},
};

#define manifest_key_len (int)(sizeof(manifest_key)/sizeof(manifest_key[0]))

static int
+
m_parse_www(struct pkg *pkg, char *buf) {
+
	while (isspace(*buf))
+
		buf++;
+

+
	pkg_set(pkg, PKG_WWW, buf);
+

+
	return (0);
+
}
+

+
static int
+
m_parse_maintainer(struct pkg *pkg, char *buf) {
+
	while (isspace(*buf))
+
		buf++;
+

+
	pkg_set(pkg, PKG_MAINTAINER, buf);
+

+
	return (0);
+
}
+

+
static int
m_parse_name(struct pkg *pkg, char *buf)
{
	/* remove trailing spaces */
@@ -85,45 +101,22 @@ m_parse_version(struct pkg *pkg, char *buf)
static int
m_parse_arch(struct pkg *pkg, char *buf)
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
-
	return (0);
-
}
+
	while (isspace(*buf))
+
		buf++;
+

+
	pkg_set(pkg, PKG_ARCH, buf);

-
static int
-
m_parse_osrelease(struct pkg *pkg, char *buf)
-
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
	return (0);
}

static int
m_parse_osversion(struct pkg *pkg, char *buf)
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
-
	return (0);
-
}
+
	while (isspace(*buf))
+
		buf++;

-
static int
-
m_parse_build_time(struct pkg *pkg, char *buf)
-
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
-
	return (0);
-
}
+
	pkg_set(pkg, PKG_OSVERSION, buf);

-
static int
-
m_parse_www(struct pkg *pkg, char *buf)
-
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
	return (0);
}

@@ -139,59 +132,54 @@ m_parse_comment(struct pkg *pkg, char *buf)
}

static int
-
m_parse_license(struct pkg *pkg, char *buf)
-
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
-
	return (0);
-
}
-

-
static int
m_parse_option(struct pkg *pkg, char *buf)
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
+
	char *value;
+

+
	while (isspace(*buf))
+
		buf++;
+

+
	value = strrchr(buf, ' ');
+
	if (value == NULL)
+
		return (-1);
+

+
	value[0] = '\0';
+
	value++;
+

+
	pkg_addoption(pkg, buf, value);
+

	return (0);
}

static int
m_parse_dep(struct pkg *pkg, char *buf)
{
-
	struct pkg *dep;
	char *buf_ptr;
-
	int nbel, i;
	size_t next;
+
	const char *name, *origin, *version;

	while (isspace(*buf))
		buf++;

	buf_ptr = buf;

-
	nbel = split_chr(buf_ptr, ' ');
+
	if (split_chr(buf_ptr, ' ') > 2)
+
		return (-1);

-
	pkg_new(&dep);
+
	next = strlen(buf_ptr);
+
	name = buf_ptr;

+
	buf_ptr += next + 1;
	next = strlen(buf_ptr);
-
	for (i = 0; i <= nbel; i++) {
-
		switch(i) {
-
			case 0:
-
				pkg_set(dep, PKG_NAME, buf_ptr);
-
				break;
-
			case 1:
-
				pkg_set(dep, PKG_ORIGIN, buf_ptr);
-
				break;
-
			case 2:
-
				pkg_set(dep, PKG_VERSION, buf_ptr);
-
				break;
-
		}
-
		buf_ptr += next + 1;
-
		next = strlen(buf_ptr);
-
	}

-
	dep->type = PKG_NOTFOUND;
-
	array_append(&pkg->deps, dep);
+
	origin = buf_ptr;
+

+
	buf_ptr += next + 1;
+
	next = strlen(buf_ptr);
+

+
	version = buf_ptr;
+

+
	pkg_adddep(pkg, name, origin, version);

	return (0);
}
@@ -199,22 +187,24 @@ m_parse_dep(struct pkg *pkg, char *buf)
static int
m_parse_conflict(struct pkg *pkg, char *buf)
{
-
	/* TODO */
-
	(void)pkg;
-
	(void)buf;
+
	while (isspace(*buf))
+
		buf++;
+

+
	pkg_addconflict(pkg, buf);
+

	return (0);
}

int
pkg_parse_manifest(struct pkg *pkg, char *buf)
{
-
	int nbl;
+
	int nbel;
	int i, j;
	char *buf_ptr;
	size_t next;


-
	nbl = split_chr(buf, '\n');
+
	nbel = split_chr(buf, '\n');

	buf_ptr = buf;
	if (!STARTS_WITH(buf, MANIFEST_FORMAT_KEY)) {
@@ -225,7 +215,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
	next = strlen(buf_ptr);
	buf_ptr += next + 1;
	next = strlen(buf_ptr);
-
	for (i = 1; i <= nbl; i++) {
+
	for (i = 1; i <= nbel; i++) {
		for (j = 0; j < manifest_key_len; j++) {
			if (STARTS_WITH(buf_ptr, manifest_key[j].key)) {
				manifest_key[j].parse(pkg, buf_ptr + strlen(manifest_key[j].key));
@@ -233,7 +223,7 @@ pkg_parse_manifest(struct pkg *pkg, char *buf)
			}
		}
		/* We need to compute `next' only if we are not at the end of the manifest */
-
		if (i != nbl) {
+
		if (i != nbel) {
			buf_ptr += next + 1;
			next = strlen(buf_ptr);
		}
modified pkg/add.c
@@ -71,8 +71,11 @@ exec_add(int argc, char **argv)
	if (ret != 0)
		return (ret);

-
	pkg_free(pkg);
+
	pkg_extract(argv[1]);
+
	pkgdb_register_pkg(db, pkg);
+

	pkgdb_close(db);
+
	pkg_free(pkg);

	return (0);
}