Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Merge branch 'master' of github.com:pkgng/pkgng
Baptiste Daroussin committed 14 years ago
commit edc1cbea7036a80e9232e6c74e33676d8549c753
parent d19c873
10 files changed +24 -30
modified libpkg/pkg.c
@@ -169,18 +169,17 @@ pkg_options(struct pkg *pkg)

int
pkg_resolvdeps(struct pkg *pkg, struct pkgdb *db) {
-
	struct pkg *p;
+
	struct pkg *p = NULL;
	struct pkgdb_it *it;
	struct pkg **deps;
	int i;

	deps = pkg_deps(pkg);
-
	pkg_new(&p);
	for (i = 0; deps[i] != NULL; i++) {
		if (deps[i]->type != PKG_INSTALLED) {
			it = pkgdb_query(db, pkg_get(deps[i], PKG_ORIGIN), MATCH_EXACT);

-
			if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == 0) {
+
			if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) {
				deps[i]->type = PKG_INSTALLED;
			} else {
				deps[i]->type = PKG_NOTFOUND;
@@ -297,9 +296,9 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
	}

	if (*pkg_p == NULL)
-
		pkg_new(pkg_p);
+
		pkg_new(pkg_p, PKG_FILE);
	else
-
		pkg_reset(*pkg_p);
+
		pkg_reset(*pkg_p, PKG_FILE);

	pkg = *pkg_p;
	pkg->type = PKG_FILE;
@@ -372,7 +371,7 @@ pkg_open2(struct pkg **pkg_p, struct archive **a, struct archive_entry **ae, con
}

int
-
pkg_new(struct pkg **pkg)
+
pkg_new(struct pkg **pkg, pkg_t type)
{
	if ((*pkg = calloc(1, sizeof(struct pkg))) == NULL)
		return(pkg_error_set(EPKG_FATAL, "%s", strerror(errno)));
@@ -403,15 +402,14 @@ pkg_new(struct pkg **pkg)
		(*pkg)->fields[fields[i].id].type = fields[i].type;
		(*pkg)->fields[fields[i].id].optional = fields[i].optional;
	}
-
	/* by default set to PKG_INSTALLED */

-
	(*pkg)->type = PKG_INSTALLED;
+
	(*pkg)->type = type;

	return (EPKG_OK);
}

void
-
pkg_reset(struct pkg *pkg)
+
pkg_reset(struct pkg *pkg, pkg_t type)
{
	if (pkg == NULL)
		return;
@@ -431,6 +429,8 @@ pkg_reset(struct pkg *pkg)
	array_reset(&pkg->files, &free);
	array_reset(&pkg->scripts, &pkg_script_free_void);
	array_reset(&pkg->options, &pkg_option_free_void);
+

+
	pkg->type = type;
}

void
@@ -644,12 +644,11 @@ pkg_adddep(struct pkg *pkg, const char *name, const char *origin, const char *ve
	if (version == NULL || version[0] == '\0')
		return (ERROR_BAD_ARG("version"));

-
	pkg_new(&dep);
+
	pkg_new(&dep, PKG_NOTFOUND);

	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
@@ -155,13 +155,13 @@ typedef void (*fetch_cb)(void *data, const char *url, off_t total, off_t done,
 * Allocate a new pkg.
 * Allocated pkg must be deallocated by pkg_free().
 */
-
int pkg_new(struct pkg **);
+
int pkg_new(struct pkg **, pkg_t type);

/**
 * Reset a pkg to its initial state.
 * Useful to avoid sequences of pkg_new() and pkg_free().
 */
-
void pkg_reset(struct pkg *);
+
void pkg_reset(struct pkg *, pkg_t type);

/**
 * Deallocate a pkg
modified libpkg/pkg_create.c
@@ -125,13 +125,15 @@ pkg_create_fakeroot(const char *outdir, pkg_formats format, const char *rootdir,
	/* Load the manifest from the metadata directory */
	if (asprintf(&manifest_path, "%s/+MANIFEST", metadatadir) == -1)
		goto cleanup;
-
	pkg_new(&pkg);
-
	pkg->type = PKG_FILE;
+

+
	pkg_new(&pkg, PKG_FILE);
	if (pkg == NULL)
		goto cleanup;
+

	ret = file_to_buffer(manifest_path, &manifest, &sz);
	if (ret != EPKG_OK)
		goto cleanup;
+

	ret = pkg_parse_manifest(pkg, manifest);

	/* Create the archive */
modified libpkg/pkg_elf.c
@@ -14,7 +14,7 @@ static int
analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
{
	struct pkg **deps;
-
	struct pkg *p;
+
	struct pkg *p = NULL;
	struct pkgdb_it *it = NULL;
	Elf *e;
	Elf_Scn *scn = NULL;
@@ -50,7 +50,6 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
	data = elf_getdata(scn, NULL);
	numdyn = shdr.sh_size / shdr.sh_entsize;

-
	pkg_new(&p);
	for (dynidx = 0; dynidx < numdyn; dynidx++) {
		if ((dyn = gelf_getdyn(data, dynidx, &dyn_mem)) == NULL)
			return (EPKG_FATAL);
@@ -66,7 +65,7 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
			if ((it = pkgdb_query_which(db, map->l_name)) == NULL)
				return (EPKG_FATAL);

-
			if (pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC) == 0) {
+
			if (pkgdb_it_next(it, &p, PKG_LOAD_BASIC) == EPKG_OK) {
				found = false;
				if (( deps = pkg_deps(pkg) ) != NULL) {
					for (i = 0; deps[i]; i++) {
@@ -81,7 +80,6 @@ analyse_elf(struct pkgdb *db, struct pkg *pkg, const char *fpath)
			}
			dlclose(handle);
		}
-
		pkg_reset(p);
		pkgdb_it_free(it);
	}
	pkg_free(p);
modified libpkg/pkgdb.c
@@ -361,12 +361,11 @@ pkgdb_it_next(struct pkgdb_it *it, struct pkg **pkg_p, int flags)
	switch (sqlite3_step(it->stmt)) {
	case SQLITE_ROW:
		if (*pkg_p == NULL)
-
			pkg_new(pkg_p);
+
			pkg_new(pkg_p, PKG_INSTALLED);
		else
-
			pkg_reset(*pkg_p);
+
			pkg_reset(*pkg_p, PKG_INSTALLED);
		pkg = *pkg_p;

-
		pkg->type = PKG_INSTALLED;
		pkg->rowid = sqlite3_column_int64(it->stmt, 0);
		pkg_set(pkg, PKG_ORIGIN, sqlite3_column_text(it->stmt, 1));
		pkg_set(pkg, PKG_NAME, sqlite3_column_text(it->stmt, 2));
modified pkg/create.c
@@ -34,7 +34,7 @@ pkg_create_matches(int argc, char **argv, match_t match, pkg_formats fmt, const
		pkgdb_close(db);
		return (-1);
	}
-
	pkg_new(&pkg);
+

	if (match != MATCH_ALL) {
		for (i = 0;i < argc; i++) {
			if ((it = pkgdb_query(db, argv[i], match)) == NULL) {
modified pkg/delete.c
@@ -20,7 +20,7 @@ usage_delete(void)
int
exec_delete(int argc, char **argv)
{
-
	struct pkg *pkg;
+
	struct pkg *pkg = NULL;
	struct pkgdb *db;
	struct pkgdb_it *it;
	match_t match = MATCH_EXACT;
@@ -69,7 +69,6 @@ exec_delete(int argc, char **argv)
		return (1);
	}

-
	pkg_new(&pkg);
	while ((ret = pkgdb_it_next(it, &pkg, flags)) == EPKG_OK) {
		if (pkg_delete(pkg, db, force) != EPKG_OK) {
			retcode++;
modified pkg/info.c
@@ -166,8 +166,6 @@ exec_info(int argc, char **argv)
	if (argc == 0)
		match = MATCH_ALL;

-
	pkg_new(&pkg);
-

	if (pkgdb_open(&db, PKGDB_DEFAULT, R_OK) != EPKG_OK) {
		pkg_error_warn("can not open database");
		return (-1);
modified pkg/register.c
@@ -55,7 +55,7 @@ exec_register(int argc, char **argv)
		return (EX_NOPERM);
	}

-
	pkg_new(&pkg);
+
	pkg_new(&pkg, PKG_INSTALLED);
	while ((ch = getopt(argc, argv, "a:f:m:i:l")) != -1) {
		switch (ch) {
			case 'f':
modified pkg/which.c
@@ -23,7 +23,7 @@ exec_which(int argc, char **argv)
{
	struct pkgdb *db;
	struct pkgdb_it *it;
-
	struct pkg *pkg;
+
	struct pkg *pkg = NULL;
	char pathabs[MAXPATHLEN];
	char pathabsdir[MAXPATHLEN];
	int retcode = 1;
@@ -48,7 +48,6 @@ exec_which(int argc, char **argv)
		return (-1);
	}

-
	pkg_new(&pkg);
	if (( ret = pkgdb_it_next(it, &pkg, PKG_LOAD_BASIC)) == EPKG_OK) {
		retcode = 0;
		printf("%s was installed by package %s-%s\n", pathabs, pkg_get(pkg, PKG_NAME),