pkg icon indicating copy to clipboard operation
pkg copied to clipboard

`pkg unlock -a` does not work

Open dearblue opened this issue 1 year ago • 0 comments

The unlock command with the -a switch will terminate with failure if it encounters the first package that is not unlocked.

The following is an example using the "ruby" package.

# pkg lock -y ruby
Locking ruby-3.2.3,1
# pkg unlock -ay
0ad-0.0.26_23: already unlocked
# pkg unlock -y ruby
Unlocking ruby-3.2.3,1

I expected the following.

# pkg lock -y ruby
Locking ruby-3.2.3,1
# pkg unlock -ay
Unlocking ruby-3.2.3,1

I don't know what behavior is preferable, so here is a patch I wrote anyway.

diff --git a/src/lock.c b/src/lock.c
index fdcf629ef..6120ae489 100644
--- a/src/lock.c
+++ b/src/lock.c
@@ -42,8 +42,8 @@ enum action {
 };
 
 static int exec_lock_unlock(int, char**, enum action);
-static int do_lock(struct pkgdb *db, struct pkg *pkg);
-static int do_unlock(struct pkgdb *db, struct pkg *pkg);
+static int do_lock(struct pkgdb *db, struct pkg *pkg, int match);
+static int do_unlock(struct pkgdb *db, struct pkg *pkg, int match);
 
 void
 usage_lock(void)
@@ -55,9 +55,11 @@ usage_lock(void)
 }
 
 static int
-do_lock(struct pkgdb *db, struct pkg *pkg)
+do_lock(struct pkgdb *db, struct pkg *pkg, int match)
 {
 	if (pkg_is_locked(pkg)) {
+		if (match == MATCH_ALL)
+			return (EPKG_OK);
 		if (!quiet)
 			pkg_printf("%n-%v: already locked\n",
 			       pkg, pkg);
@@ -76,9 +78,11 @@ do_lock(struct pkgdb *db, struct pkg *pkg)
 
 
 static int
-do_unlock(struct pkgdb *db, struct pkg *pkg)
+do_unlock(struct pkgdb *db, struct pkg *pkg, int match)
 {
 	if (!pkg_is_locked(pkg)) {
+		if (match == MATCH_ALL)
+			return (EPKG_OK);
 		if (!quiet)
 			pkg_printf("%n-%v: already unlocked\n", pkg, pkg);
 		return (EPKG_FATAL);
@@ -124,9 +128,9 @@ do_lock_unlock(struct pkgdb *db, int match, const char *pkgname,
 	}
 	tll_foreach(pkgs, p) {
 		if (action == LOCK)
-			retcode = do_lock(db, p->item);
+			retcode = do_lock(db, p->item, match);
 		else
-			retcode = do_unlock(db, p->item);
+			retcode = do_unlock(db, p->item, match);
 
 		if (retcode != EPKG_OK) {
 			exitcode = EXIT_FAILURE;

dearblue avatar Apr 26 '24 11:04 dearblue