Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
Forbid pkg delete pkg without -f (fixes #310)
Baptiste Daroussin committed 13 years ago
commit 5e25ce2ec886497572f48bb146ea0d481d3378d3
parent 68c7c37
1 file changed +13 -0
modified pkg/delete.c
@@ -28,6 +28,7 @@

#include <err.h>
#include <stdio.h>
+
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#include <libutil.h>
@@ -59,6 +60,8 @@ exec_delete(int argc, char **argv)
	bool dry_run = false;
	int retcode = EX_SOFTWARE;
	int recursive = 0;
+
	bool haspkg = false;
+
	const char *origin;

	while ((ch = getopt(argc, argv, "afgnqRXxy")) != -1) {
		switch (ch) {
@@ -121,9 +124,19 @@ exec_delete(int argc, char **argv)
		goto cleanup;

	while (pkgdb_it_next(it, &pkg, flags) == EPKG_OK) {
+
		pkg_get(pkg, PKG_ORIGIN, &origin);
+
		if (!force && !haspkg) {
+
			if (strcmp(origin, "ports-mgmt/pkg") == 0)
+
				haspkg = true;
+
		}
		pkg_jobs_add(jobs, pkg);
		pkg = NULL;
	}
+
	if (haspkg && !force) {
+
		warnx("You are about to delete 'ports-mgmt/pkg' which is really"
+
		    "dangerous, you can't do that without specifying -f");
+
		goto cleanup;
+
	}

	/* check if we have something to deinstall */
	if (pkg_jobs_is_empty(jobs)) {