diff mbox series

[OpenWrt-Devel,RFC] opkg: add License to info command

Message ID 20190511081257.3791-1-mail@aparcar.org
State Superseded
Headers show
Series [OpenWrt-Devel,RFC] opkg: add License to info command | expand

Commit Message

Paul Spooren May 11, 2019, 8:12 a.m. UTC
show license in `opkg info <pkg_name>`.

Signed-off-by: Paul Spooren <mail@aparcar.org>
---
This patch isn't complete yet. It show the license info as long as the package
isn't installed. Once it's installed it seems to forget the information. I can't
figure out why. Also printing `opkg list` doesn't add the License, neither for
installed nor available.

 libopkg/opkg_cmd.c  |  3 +++
 libopkg/pkg.c       | 10 ++++++++++
 libopkg/pkg.h       |  1 +
 libopkg/pkg_parse.c |  5 +++++
 libopkg/pkg_parse.h |  1 +
 5 files changed, 20 insertions(+)

Comments

Jo-Philipp Wich May 13, 2019, 1:07 p.m. UTC | #1
Hi,

please make sure that the license info is only parsed when it is required by
the toplevel command being executed, look at the other usages of the PFM_*
macros in the source.

Without this, the in-memory representation of the package trees will consume
way more RAM due to the redundant license string copies held by each abstract
package node.

~ Jo
diff mbox series

Patch

diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c
index c823df8..81f9a29 100644
--- a/libopkg/opkg_cmd.c
+++ b/libopkg/opkg_cmd.c
@@ -45,7 +45,10 @@  static void print_pkg(pkg_t * pkg)
 {
 	char *version = pkg_version_str_alloc(pkg);
 	char *description = pkg_get_string(pkg, PKG_DESCRIPTION);
+	char *license = pkg_get_string(pkg, PKG_LICENSE);
 	printf("%s - %s", pkg->name, version);
+	if (license)
+		printf(" - %s", license);
 	if (conf->size)
 		printf(" - %lu", (unsigned long) pkg_get_int(pkg, PKG_SIZE));
 	if (description)
diff --git a/libopkg/pkg.c b/libopkg/pkg.c
index e5bfe6f..1971689 100644
--- a/libopkg/pkg.c
+++ b/libopkg/pkg.c
@@ -777,6 +777,15 @@  void pkg_formatted_field(FILE * fp, pkg_t * pkg, const char *field)
 			}
 		}
 		break;
+	case 'l':
+	case 'L':
+		if (strcasecmp(field, "License") == 0) {
+			p = pkg_get_string(pkg, PKG_LICENSE);
+			if (p) {
+				fprintf(fp, "License: %s\n", p);
+			}
+		}
+		break;
 	case 'm':
 	case 'M':
 		if (strcasecmp(field, "Maintainer") == 0) {
@@ -926,6 +935,7 @@  void pkg_formatted_info(FILE * fp, pkg_t * pkg)
 	pkg_formatted_field(fp, pkg, "Package");
 	pkg_formatted_field(fp, pkg, "Version");
 	pkg_formatted_field(fp, pkg, "Depends");
+	pkg_formatted_field(fp, pkg, "License");
 	pkg_formatted_field(fp, pkg, "Recommends");
 	pkg_formatted_field(fp, pkg, "Suggests");
 	pkg_formatted_field(fp, pkg, "Provides");
diff --git a/libopkg/pkg.h b/libopkg/pkg.h
index 600fc9e..0065043 100644
--- a/libopkg/pkg.h
+++ b/libopkg/pkg.h
@@ -79,6 +79,7 @@  typedef enum pkg_state_status pkg_state_status_t;
 
 enum pkg_fields {
 	PKG_MAINTAINER,
+	PKG_LICENSE,
 	PKG_PRIORITY,
 	PKG_SOURCE,
 	PKG_TAGS,
diff --git a/libopkg/pkg_parse.c b/libopkg/pkg_parse.c
index 0baa4db..e0389df 100644
--- a/libopkg/pkg_parse.c
+++ b/libopkg/pkg_parse.c
@@ -269,6 +269,11 @@  int pkg_parse_line(void *ptr, char *line, uint mask)
 			pkg_set_int(pkg, PKG_INSTALLED_TIME, strtoul(line + strlen("Installed-Time") + 1, NULL, 0));
 		}
 		break;
+		case 'l':
+		case 'L':
+		if (is_field("License", line))
+			pkg_set_string(pkg, PKG_LICENSE, line + strlen("License") + 1);
+		break;
 
 	case 'M':
 		if ((mask & PFM_MD5SUM) && (is_field("MD5sum:", line) || is_field("MD5Sum:", line)))
diff --git a/libopkg/pkg_parse.h b/libopkg/pkg_parse.h
index d1f901a..ccb97aa 100644
--- a/libopkg/pkg_parse.h
+++ b/libopkg/pkg_parse.h
@@ -54,6 +54,7 @@  int pkg_parse_line(void *ptr, char *line, uint mask);
 #define PFM_SUGGESTS		(1 << 25)
 #define PFM_TAGS		(1 << 26)
 #define PFM_VERSION		(1 << 27)
+#define PFM_LICENSE		(1 << 28)
 
 #define PFM_ALL	(~(uint)0)