Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
remove pkg_add2 and pkg_delete2
Baptiste Daroussin committed 14 years ago
commit e41281bf472e9d60b2e11aa7552f254ec27659d3
parent 6196d9f
5 files changed +34 -36
modified libpkg/pkg.h
@@ -650,8 +650,11 @@ int pkgdb_compact(struct pkgdb *db);
 * @param path The path to the package archive file on the local disk
 * @return An error code.
 */
-
int pkg_add(struct pkgdb *db, const char *path);
-
int pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic);
+
int pkg_add(struct pkgdb *db, const char *path, int flags);
+

+
#define PKG_ADD_UPGRADE (1 << 0)
+
#define PKG_ADD_UPGRADE_NEW (1 << 1)
+
#define PKG_ADD_AUTOMATIC (1 << 2)

/**
 * Allocate a new pkg_jobs.
@@ -712,8 +715,9 @@ int pkg_create_fakeroot(const char *, pkg_formats, const char *, const char *);
 * required by other packages.
 * @return An error code.
 */
-
int pkg_delete(struct pkg *pkg, struct pkgdb *db, int force);
-
int pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade);
+
int pkg_delete(struct pkg *pkg, struct pkgdb *db, int flags);
+
#define PKG_DELETE_FORCE (1<<0)
+
#define PKG_DELETE_UPGRADE (1<<0)

int pkg_repo_fetch(struct pkg *pkg);
int pkg_repo_verify(const char *path, unsigned char *sig, unsigned int sig_len);
modified libpkg/pkg_add.c
@@ -79,13 +79,7 @@ do_extract(struct archive *a, struct archive_entry *ae)
}

int
-
pkg_add(struct pkgdb *db, const char *path)
-
{
-
	return (pkg_add2(db, path, 0, 0));
-
}
-

-
int
-
pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
+
pkg_add(struct pkgdb *db, const char *path, int flags)
{
	struct archive *a;
	struct archive_entry *ae;
@@ -116,7 +110,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
		goto cleanup;
	}

-
	if (automatic == 1)
+
	if (flags & PKG_ADD_AUTOMATIC)
		pkg_set_automatic(pkg);

	if (uname(&u) != 0) {
@@ -178,7 +172,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
					 ext);

			if (access(dpath, F_OK) == 0) {
-
				if (pkg_add2(db, dpath, 0, 1) != EPKG_OK) {
+
				if (pkg_add(db, dpath, PKG_ADD_AUTOMATIC) != EPKG_OK) {
					retcode = EPKG_FATAL;
					goto cleanup;
				}
@@ -192,7 +186,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)

	/* register the package before installing it in case there are
	 * problems that could be caught here. */
-
	if (upgrade == 0)
+
	if (flags & PKG_ADD_UPGRADE)
		retcode = pkgdb_register_pkg(db, pkg, 0);
	else
		retcode = pkgdb_register_pkg(db, pkg, 1);
@@ -202,7 +196,7 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
	/*
	 * Execute pre-install scripts
	 */
-
	if (upgrade != 2)
+
	if (flags ^ PKG_ADD_UPGRADE_NEW)
		pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL);

	/*
@@ -218,13 +212,13 @@ pkg_add2(struct pkgdb *db, const char *path, int upgrade, int automatic)
	/*
	 * Execute post install scripts
	 */
-
	if (upgrade == 2)
+
	if (flags & PKG_ADD_UPGRADE_NEW)
		pkg_script_run(pkg, PKG_SCRIPT_POST_UPGRADE);
	else
		pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);

	cleanup_reg:
-
	if (upgrade == 0)
+
	if (flags ^ PKG_ADD_UPGRADE)
		pkgdb_register_finale(db, retcode);

	cleanup:
modified libpkg/pkg_delete.c
@@ -13,13 +13,7 @@
#include "pkg_util.h"

int
-
pkg_delete(struct pkg *pkg, struct pkgdb *db, int force)
-
{
-
	return (pkg_delete2(pkg, db, force, 0));
-
}
-

-
int
-
pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade)
+
pkg_delete(struct pkg *pkg, struct pkgdb *db, int flags)
{
	struct pkg_dep *rdep = NULL;
	int ret;
@@ -47,19 +41,19 @@ pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade)
	if ((ret = pkgdb_load_mtree(db, pkg)) != EPKG_OK)
		return (ret);

-
	if (!upgrade)
-
		pkg_emit_deinstall_begin(pkg);
-
	else
+
	if (flags & PKG_DELETE_UPGRADE)
		pkg_emit_upgrade_begin(pkg);
+
	else
+
		pkg_emit_deinstall_begin(pkg);

	/* If there are dependencies */
	if (pkg_rdeps(pkg, &rdep) == EPKG_OK) {
-
		pkg_emit_required(pkg, force);
-
		if (!force)
+
		pkg_emit_required(pkg, flags & PKG_DELETE_FORCE);
+
		if (flags ^ PKG_DELETE_FORCE)
			return (EPKG_REQUIRED);
	}

-
	if (upgrade) {
+
	if (flags & PKG_DELETE_UPGRADE) {
		if (( ret = pkg_script_run(pkg, PKG_SCRIPT_PRE_UPGRADE)) != EPKG_OK )
			return (ret);
	} else {
@@ -67,17 +61,17 @@ pkg_delete2(struct pkg *pkg, struct pkgdb *db, int force, int upgrade)
			return (ret);
	}

-
	if ((ret = pkg_delete_files(pkg, force)) != EPKG_OK)
+
	if ((ret = pkg_delete_files(pkg, flags & PKG_DELETE_FORCE)) != EPKG_OK)
		return (ret);

-
	if (!upgrade)
+
	if (flags ^ PKG_DELETE_UPGRADE)
		if ((ret = pkg_script_run(pkg, PKG_SCRIPT_POST_DEINSTALL)) != EPKG_OK)
			return (ret);

-
	if ((ret = pkg_delete_dirs(db, pkg, force)) != EPKG_OK)
+
	if ((ret = pkg_delete_dirs(db, pkg, flags & PKG_DELETE_FORCE)) != EPKG_OK)
		return (ret);

-
	if (!upgrade)
+
	if (flags ^ PKG_DELETE_UPGRADE)
		pkg_emit_deinstall_finished(pkg);

	return (pkgdb_unregister_pkg(db, pkg_get(pkg, PKG_ORIGIN)));
modified libpkg/pkg_jobs.c
@@ -124,6 +124,7 @@ pkg_jobs_install(struct pkg_jobs *j)
	const char *cachedir;
	char path[MAXPATHLEN + 1];
	int ret = EPKG_OK;
+
	int flags = 0;

	STAILQ_INIT(&pkg_queue);

@@ -159,6 +160,7 @@ pkg_jobs_install(struct pkg_jobs *j)
	/* Install */
	sql_exec(j->db->sqlite, "SAVEPOINT upgrade;");
	while (pkg_jobs(j, &p) == EPKG_OK) {
+
		flags = 0;
		it = pkgdb_integrity_conflict_local(j->db, pkg_get(p, PKG_ORIGIN));

		if (it != NULL) {
@@ -194,7 +196,11 @@ pkg_jobs_install(struct pkg_jobs *j)
			}
		}

-
		if (pkg_add2(j->db, path, 1, pkg_is_automatic(p)) != EPKG_OK) {
+
		flags |= PKG_ADD_UPGRADE;
+
		if (pkg_is_automatic(p))
+
			flags |= PKG_ADD_AUTOMATIC;
+

+
		if (pkg_add(j->db, path, flags) != EPKG_OK) {
			sql_exec(j->db->sqlite, "ROLLBACK TO upgrade;");
			return (EPKG_FATAL);
		}
modified pkg/add.c
@@ -65,7 +65,7 @@ exec_add(int argc, char **argv)
		} else
			file = argv[i];

-
		if (pkg_add(db, file) != EPKG_OK) {
+
		if (pkg_add(db, file, 0) != EPKG_OK) {
			continue;
		}
	}