[PATCH opkg-lede] libopkg: make "info" & "status" return error for no matching packages

Rafał Miłecki zajec5 at gmail.com
Fri Aug 2 04:07:36 PDT 2024


From: Rafał Miłecki <rafal at milecki.pl>

This makes checking for packages easier.

Example:
$ opkg status blo0ckd; echo $?
254

Signed-off-by: Rafał Miłecki <rafal at milecki.pl>
---
 libopkg/opkg_cmd.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index 6547775..f82e10a 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -795,6 +795,7 @@ static int opkg_info_status_cmd(int argc, char **argv, int installed_only)
 	pkg_t *pkg;
 	char *pkg_name = NULL;
 	conffile_list_t *cl;
+	int err;
 
 	if (argc > 0) {
 		pkg_name = argv[0];
@@ -806,11 +807,13 @@ static int opkg_info_status_cmd(int argc, char **argv, int installed_only)
 	else
 		pkg_hash_fetch_available(available);
 
+	err = -ENOENT;
 	for (i = 0; i < available->len; i++) {
 		pkg = available->pkgs[i];
 		if (pkg_name && fnmatch(pkg_name, pkg->name, conf->nocase)) {
 			continue;
 		}
+		err = 0;
 
 		pkg_formatted_info(stdout, pkg);
 
@@ -831,7 +834,7 @@ static int opkg_info_status_cmd(int argc, char **argv, int installed_only)
 	}
 	pkg_vec_free(available);
 
-	return 0;
+	return err;
 }
 
 static int opkg_info_cmd(int argc, char **argv)
-- 
2.35.3




More information about the openwrt-devel mailing list