diff mbox series

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

Message ID 20240802110736.14946-1-zajec5@gmail.com
State Under Review
Delegated to: Rafał Miłecki
Headers show
Series [opkg-lede] libopkg: make "info" & "status" return error for no matching packages | expand

Commit Message

Rafał Miłecki Aug. 2, 2024, 11:07 a.m. UTC
From: Rafał Miłecki <rafal@milecki.pl>

This makes checking for packages easier.

Example:
$ opkg status blo0ckd; echo $?
254

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

Patch

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)