Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Use the same mecanism for pkg register as for pkg to register a package
Baptiste Daroussin committed 11 years ago
commit 9da0002282e33cc72f8c40c34dc46ab9cf88a641
parent 71e1787
6 files changed +51 -29
modified libpkg/libpkg.ver
@@ -2,6 +2,7 @@ LIBPKG_1.3 {
global:
	pkg_add;
	pkg_add_from_remote;
+
	pkg_add_port;
	pkg_addannotation;
	pkg_addcategory;
	pkg_addconflict;
modified libpkg/pkg.c
@@ -1607,9 +1607,6 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
	char spath[MAXPATHLEN];
	char dpath[MAXPATHLEN];

-
	/* Execute pre-install scripts */
-
	pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL);
-

	if (packing_init(&pack, dest, 0, true) != EPKG_OK) {
		/* TODO */
		return EPKG_FATAL;
@@ -1629,9 +1626,6 @@ pkg_copy_tree(struct pkg *pkg, const char *src, const char *dest)
		    file->uname, file->gname, file->perm);
	}

-
	/* Execute post-install scripts */
-
	pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);
-

	return (packing_finish(pack));
}

modified libpkg/pkg.h.in
@@ -1814,5 +1814,7 @@ bool pkg_audit_is_vulnerable(struct pkg_audit *audit, struct pkg *pkg,
void pkg_audit_free (struct pkg_audit *audit);
char *pkg_utils_tokenize(char **);
int pkg_utils_count_spaces(const char *);
+
int pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *root, \
+
    const char *locationn, bool testing, bool old);

#endif
modified libpkg/pkg_ports.c
@@ -1152,3 +1152,44 @@ ports_parse_plist(struct pkg *pkg, const char *plist, const char *stage)

	return (ret);
}
+

+
int
+
pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
+
    const char *location, bool testing, bool old)
+
{
+
	int rc = EPKG_OK;
+

+
	if (location != NULL)
+
		pkg_addannotation(pkg, "relocated", location);
+

+
	pkg_emit_install_begin(pkg);
+

+
	if (!old)
+
		rc = pkgdb_register_pkg(db, pkg, 0, 0);
+

+
	if (rc != EPKG_OK)
+
		goto cleanup;
+

+
	if (!testing) {
+
		/* Execute pre-install scripts */
+
		pkg_script_run(pkg, PKG_SCRIPT_PRE_INSTALL);
+

+
		if (input_path != NULL)
+
			pkg_copy_tree(pkg, input_path, \
+
			    location ? location : "/");
+

+
		/* Execute post-install scripts */
+
		pkg_script_run(pkg, PKG_SCRIPT_POST_INSTALL);
+
	}
+

+
	if (rc == EPKG_OK)
+
		pkg_emit_install_finished(pkg);
+

+
cleanup:
+
	if (old)
+
		return (pkg_register_old(pkg));
+

+
	pkgdb_register_finale(db, rc);
+

+
	return (rc);
+
}
modified src/register.c
@@ -327,29 +327,13 @@ exec_register(int argc, char **argv)
			pkg_suggest_arch(pkg, arch, false);
	}

-
	if (!testing_mode && input_path != NULL)
-
		pkg_copy_tree(pkg, input_path, location ? location : "/");
-
	
-
	if (location != NULL)
-
		pkg_addannotation(pkg, "relocated", location);
-

-
	if (old) {
-
		if (pkg_register_old(pkg) != EPKG_OK)
-
			retcode = EX_SOFTWARE;
-
	} else {
-
		if (pkgdb_register_ports(db, pkg) != EPKG_OK)
-
			retcode = EX_SOFTWARE;
-
	}
+
	retcode = pkg_add_port(db, pkg, input_path, location, testing_mode, \
+
	    old);

	if (!legacy && pkg_has_message(pkg))
		pkg_printf("%M\n", pkg);

-
	if (!old) {
-
		pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);
-
		pkgdb_close(db);
-
	}
-

	pkg_free(pkg);

-
	return (retcode);
+
	return (retcode != EPKG_OK ? EX_SOFTWARE : EX_OK);
}
modified tests/frontend/register.shin
@@ -1,11 +1,11 @@
#! /usr/bin/env atf-sh

atf_test_case register
-
register_head() {
-
	atf_set "descr" "testing pkg register"
+
register_conflicts_head() {
+
	atf_set "descr" "testing pkg register conflicts"
}

-
register_body() {
+
register_conflicts_body() {
	export INSTALL_AS_USER=yes
	export PKG_DBDIR=.

@@ -71,5 +71,5 @@ atf_init_test_cases() {

	unset PKG_DBDIR

-
	atf_add_test_case register
+
	atf_add_test_case register_conflicts
}