Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
register: implement -N to disable registration in the database
Baptiste Daroussin committed 4 years ago
commit b7e41c16fe4f0ab71dbf7003bef08475ae039536
parent 3753465
4 files changed +52 -18
modified docs/pkg-register.8
@@ -14,7 +14,7 @@
.\"
.\"     @(#)pkg.8
.\"
-
.Dd November 02, 2014
+
.Dd August 13, 2021
.Dt PKG-REGISTER 8
.Os
.Sh NAME
@@ -22,22 +22,22 @@
.Nd register a package into the local package database
.Sh SYNOPSIS
.Nm
-
.Op Fl dlt
+
.Op Fl dltN
.Op Fl f Ar plist-file
.Fl m Ar metadatadir
.Fl i Ar input-path
.Nm
-
.Op Fl dlt
+
.Op Fl dltN
.Fl M Ar metadatafile
.Pp
.Nm
-
.Op Cm --{debug,legacy,test}
+
.Op Cm --{debug,legacy,test,no-registration}
.Op Cm --relocate Ar location
.Op Cm --plist Ar plist-file
.Cm --metadata Ar metadatadir
.Cm --root Ar input-path
.Nm
-
.Op Cm --{debug,legacy,test}
+
.Op Cm --{debug,legacy,test,no-registration}
.Op Cm --relocate Ar location
.Cm --manifest Ar metadatafile
.Sh DESCRIPTION
@@ -114,6 +114,9 @@ For more information please refer to
.Xr pkg-autoremove 8 .
.It Fl d , Cm --debug
Enable debugging output.
+
.It Fl N , Cm --no-registration
+
Disable registration in the package database, the files will be installed,
+
the scripts will be executed.
.It Fl f Ar plist-file , Cm --plist Ar plist-file
Specifies a
.Fa pkg-plist
modified libpkg/pkg_ports.c
@@ -1180,6 +1180,10 @@ ports_parse_plist(struct pkg *pkg, const char *plist, const char *stage)
	return (rc);
}

+
/*
+
 * if the provided database is NULL then we don't want to register the package
+
 * in the database aka NO_PKG_REGISTER
+
 */
int
pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
    const char *reloc, bool testing)
@@ -1189,7 +1193,7 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
	xstring *message;
	struct pkg_message *msg;

-
	if (pkg_is_installed(db, pkg->name) != EPKG_END) {
+
	if (db != NULL && pkg_is_installed(db, pkg->name) != EPKG_END) {
		return(EPKG_INSTALLED);
	}

@@ -1202,10 +1206,12 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,

	pkg_emit_install_begin(pkg);

-
	rc = pkgdb_register_pkg(db, pkg, 0, NULL);
+
	if (db != NULL) {
+
		rc = pkgdb_register_pkg(db, pkg, 0, NULL);

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

	if (!testing) {
		/* Execute pre-install scripts */
@@ -1218,7 +1224,8 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
			pkg_unregister_cleanup_callback(pkg_rollback_cb, pkg);
			if (rc != EPKG_OK) {
				pkg_rollback_pkg(pkg);
-
				pkg_delete_dirs(db, pkg, NULL);
+
				if (db != NULL)
+
					pkg_delete_dirs(db, pkg, NULL);
			}
		}

@@ -1247,7 +1254,8 @@ pkg_add_port(struct pkgdb *db, struct pkg *pkg, const char *input_path,
	}

cleanup:
-
	pkgdb_register_finale(db, rc, NULL);
+
	if (db != NULL)
+
		pkgdb_register_finale(db, rc, NULL);

	return (rc);
}
modified src/register.c
@@ -42,9 +42,9 @@
void
usage_register(void)
{
-
	fprintf(stderr, "Usage: pkg register [-ldt] [-i <input-path>]"
+
	fprintf(stderr, "Usage: pkg register [-ldtN] [-i <input-path>]"
	                " [-f <plist-file>] -m <metadatadir>\n");
-
	fprintf(stderr, "       pkg register [-ldt] [-i <input_path>]"
+
	fprintf(stderr, "       pkg register [-ldtN] [-i <input_path>]"
		        " -M <manifest>\n\n");
	fprintf(stderr, "For more information see 'pkg help register'.\n");
}
@@ -63,6 +63,7 @@ exec_register(int argc, char **argv)

	bool		 legacy        = false;
	bool		 testing_mode  = false;
+
	bool		 reg_in_db = true;

	int		 ch;
	int		 ret     = EPKG_OK;
@@ -75,6 +76,7 @@ exec_register(int argc, char **argv)
		{ "legacy",	no_argument,		NULL,	'l' },
		{ "manifest",	required_argument,	NULL,	'M' },
		{ "metadata",	required_argument,	NULL,	'm' },
+
		{ "no-registration", no_argument,	NULL,	'N' },
		{ "plist",	required_argument,	NULL,	'f' },
		{ "relocate",	required_argument,	NULL, 	1 },
		{ "root",	required_argument,	NULL,	'i' },
@@ -85,7 +87,7 @@ exec_register(int argc, char **argv)
	if (pkg_new(&pkg, PKG_INSTALLED) != EPKG_OK)
		err(EXIT_FAILURE, "malloc");

-
	while ((ch = getopt_long(argc, argv, "+Adf:i:lM:m:t", longopts, NULL)) != -1) {
+
	while ((ch = getopt_long(argc, argv, "+Adf:i:lM:m:Nt", longopts, NULL)) != -1) {
		switch (ch) {
		case 'A':
		case 'd':
@@ -106,6 +108,9 @@ exec_register(int argc, char **argv)
		case 'm':
			mdir = optarg;
			break;
+
		case 'N':
+
			reg_in_db = false;
+
			break;
		case 't':
			testing_mode = true;
			break;
@@ -179,12 +184,12 @@ exec_register(int argc, char **argv)
	}


-
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
+
	if (reg_in_db && pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK) {
		pkg_free(pkg);
		return (EXIT_FAILURE);
	}

-
	if (pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) {
+
	if (db != NULL && pkgdb_obtain_lock(db, PKGDB_LOCK_EXCLUSIVE) != EPKG_OK) {
		pkgdb_close(db);
		pkg_free(pkg);
		warnx("Cannot get an exclusive lock on a database, it is locked by another process");
@@ -199,7 +204,8 @@ exec_register(int argc, char **argv)
	}

	pkg_free(pkg);
-
	pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);
+
	if (db != NULL)
+
		pkgdb_release_lock(db, PKGDB_LOCK_EXCLUSIVE);

	return (retcode != EPKG_OK ? EXIT_FAILURE : EXIT_SUCCESS);
}
modified tests/frontend/register.sh
@@ -6,7 +6,8 @@ tests_init \
	register_conflicts \
	register_message \
	prefix_is_a_symlink \
-
	file_not_found
+
	file_not_found \
+
	no_pkg_register

register_conflicts_body() {
	mkdir -p teststage/${TMPDIR}
@@ -123,3 +124,19 @@ file_not_found_body()
		-s exit:1 \
		pkg -r ${TMPDIR}/target register -M ${TMPDIR}/test.ucl -f ${TMPDIR}/plist -i ${TMPDIR}
}
+

+
no_pkg_register_body()
+
{
+
	atf_check -s exit:0 sh ${RESOURCEDIR}/test_subr.sh new_pkg "test" "test" "1" "/prefix"
+
	echo "/foo" > plist
+
	touch foo
+
	mkdir -p ${TMPDIR}/target
+
	atf_check \
+
		-o ignore \
+
		-e empty \
+
		-s exit:0 \
+
		pkg -r ${TMPDIR}/target register -N -M ${TMPDIR}/test.ucl -f ${TMPDIR}/plist -i ${TMPDIR}
+
	test -f ${TMPDIR}/target/foo || atf_fail "foo file has not been installed"
+
	atf_check \
+
		pkg -r ${TMPDIR}/target info
+
}