Radish alpha
H
rad:z3QDZAW2FAfuLvihrhiyDC9fAD8G9
HardenedBSD Package Manager
Radicle
Git
pkg-{delete,autoremove}: Use a readonly lock in dry run
Bryan Drewery committed 11 years ago
commit 19d843aaee09efdcc3d828713ba191656618631e
parent 8e73f87
2 files changed +8 -4
modified src/autoremove.c
@@ -53,6 +53,7 @@ exec_autoremove(int argc, char **argv)
	nbactions = nbdone = 0;
	pkg_flags f = PKG_FLAG_FORCE;
	bool rc = false;
+
	int lock_type = PKGDB_LOCK_ADVISORY;

	struct option longopts[] = {
		{ "dry-run",	no_argument,	NULL,	'n' },
@@ -66,6 +67,7 @@ exec_autoremove(int argc, char **argv)
		case 'n':
			f |= PKG_FLAG_DRY_RUN;
			dry_run = true;
+
			lock_type = PKGDB_LOCK_READONLY;
			break;
		case 'q':
			quiet = true;
@@ -106,7 +108,7 @@ exec_autoremove(int argc, char **argv)
		return (EX_IOERR);
	}

-
	if (pkgdb_obtain_lock(db, PKGDB_LOCK_ADVISORY) != EPKG_OK) {
+
	if (pkgdb_obtain_lock(db, lock_type) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get an advisory lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
@@ -144,7 +146,7 @@ exec_autoremove(int argc, char **argv)

cleanup:
	pkg_jobs_free(jobs);
-
	pkgdb_release_lock(db, PKGDB_LOCK_ADVISORY);
+
	pkgdb_release_lock(db, lock_type);
	pkgdb_close(db);

	return (retcode);
modified src/delete.c
@@ -57,6 +57,7 @@ exec_delete(int argc, char **argv)
	int		 retcode = EX_SOFTWARE;
	int		 ch;
	int		 i;
+
	int		 lock_type = PKGDB_LOCK_ADVISORY;

	struct option longopts[] = {
		{ "all",			no_argument,	NULL,	'a' },
@@ -98,6 +99,7 @@ exec_delete(int argc, char **argv)
			break;
		case 'n':
			f |= PKG_FLAG_DRY_RUN;
+
			lock_type = PKGDB_LOCK_READONLY;
			dry_run = true;
			break;
		case 'q':
@@ -146,7 +148,7 @@ exec_delete(int argc, char **argv)
	if (pkgdb_open(&db, PKGDB_DEFAULT) != EPKG_OK)
		return (EX_IOERR);

-
	if (pkgdb_obtain_lock(db, PKGDB_LOCK_ADVISORY) != EPKG_OK) {
+
	if (pkgdb_obtain_lock(db, lock_type) != EPKG_OK) {
		pkgdb_close(db);
		warnx("Cannot get an advisory lock on a database, it is locked by another process");
		return (EX_TEMPFAIL);
@@ -222,7 +224,7 @@ exec_delete(int argc, char **argv)
	retcode = EX_OK;

cleanup:
-
	pkgdb_release_lock(db, PKGDB_LOCK_ADVISORY);
+
	pkgdb_release_lock(db, lock_type);
	pkg_jobs_free(jobs);
	pkgdb_close(db);