From 6da083fc24e4f1ef0363957074148d1bc11cef83 Mon Sep 17 00:00:00 2001
From: Timo Teräs <timo.teras@iki.fi>
Date: Wed, 19 Jun 2013 20:55:01 +0300
Subject: all: few behavioural regression fixes

Wildcard matching with no names should match all packages only for
info and search applet. "apk del" would otherwise try to delete
everything, etc.

Fix also interactive mode to ask questions only if we are actually
changing something.
---
 src/apk_package.h | 1 +
 src/commit.c      | 2 +-
 src/database.c    | 2 ++
 src/info.c        | 4 +++-
 src/search.c      | 4 +++-
 src/ver.c         | 5 +++--
 6 files changed, 13 insertions(+), 5 deletions(-)

diff --git a/src/apk_package.h b/src/apk_package.h
index db3965b..2d8a431 100644
--- a/src/apk_package.h
+++ b/src/apk_package.h
@@ -42,6 +42,7 @@ struct apk_provider;
 #define APK_DEP_CONFLICTS		0x04
 #define APK_FOREACH_INSTALLED		0x10
 #define APK_FOREACH_MARKED		0x20
+#define APK_FOREACH_NULL_MATCHES_ALL	0x40
 #define APK_FOREACH_GENID_MASK		0xffffff00
 
 struct apk_sign_ctx {
diff --git a/src/commit.c b/src/commit.c
index af9e34c..fc4fafd 100644
--- a/src/commit.c
+++ b/src/commit.c
@@ -259,7 +259,7 @@ int apk_solver_commit_changeset(struct apk_database *db,
 				"disk space will be freed." :
 				"additional disk space will be used.");
 		}
-		if (changeset->changes->num > 0 &&
+		if (changeset->num_total_changes > 0 &&
 		    (apk_flags & APK_INTERACTIVE)) {
 			printf("Do you want to continue [Y/n]? ");
 			fflush(stdout);
diff --git a/src/database.c b/src/database.c
index 72e568d..2360bda 100644
--- a/src/database.c
+++ b/src/database.c
@@ -2741,6 +2741,8 @@ void apk_name_foreach_matching(struct apk_database *db, struct apk_string_array
 	};
 
 	if (filter == NULL || filter->num == 0) {
+		if (!(match & APK_FOREACH_NULL_MATCHES_ALL))
+			return;
 		apk_string_array_init(&mctx.filter);
 		goto all;
 	}
diff --git a/src/info.c b/src/info.c
index 15dad1e..9eb9e78 100644
--- a/src/info.c
+++ b/src/info.c
@@ -399,7 +399,9 @@ static int info_main(void *ctx, struct apk_database *db, struct apk_string_array
 
 	if (args->num > 0) {
 		/* Print info on given names */
-		apk_name_foreach_matching(db, args, apk_foreach_genid(), print_name_info, ctx);
+		apk_name_foreach_matching(
+			db, args, APK_FOREACH_NULL_MATCHES_ALL | apk_foreach_genid(),
+			print_name_info, ctx);
 	} else {
 		/* Print all installed packages */
 		list_for_each_entry(ipkg, &db->installed.packages, installed_pkgs_list)
diff --git a/src/search.c b/src/search.c
index 3c323db..2b7b5e1 100644
--- a/src/search.c
+++ b/src/search.c
@@ -157,7 +157,9 @@ static int search_main(void *pctx, struct apk_database *db, struct apk_string_ar
 			*pmatch = tmp;
 		}
 	}
-	apk_name_foreach_matching(db, args, apk_foreach_genid(), print_result, ctx);
+	apk_name_foreach_matching(
+		db, args, APK_FOREACH_NULL_MATCHES_ALL | apk_foreach_genid(),
+		print_result, ctx);
 	return 0;
 }
 
diff --git a/src/ver.c b/src/ver.c
index 5f340c4..94220a9 100644
--- a/src/ver.c
+++ b/src/ver.c
@@ -174,8 +174,9 @@ static int ver_main(void *pctx, struct apk_database *db, struct apk_string_array
 	if (apk_verbosity > 0)
 		printf("%-42sAvailable:\n", "Installed:");
 
-	apk_name_foreach_matching(db, args, apk_foreach_genid(),
-				  ver_print_package_status, ctx);
+	apk_name_foreach_matching(
+		db, args, APK_FOREACH_NULL_MATCHES_ALL | apk_foreach_genid(),
+		ver_print_package_status, ctx);
 
 	return 0;
 }
-- 
cgit v1.2.3-70-g09d2