diff options
| author | Daniel Golle | 2021-03-14 22:28:05 +0000 |
|---|---|---|
| committer | Daniel Golle | 2021-03-14 22:50:41 +0000 |
| commit | d3a63b327383a2ac1a8f925a58a2f6a7808f5181 (patch) | |
| tree | 881ce5520a0fe9140bc5f0df51e7fc0cbe355e82 | |
| parent | d71856a4f137dc9fb890c5e777790e2c51fde921 (diff) | |
| download | opkg-lede-d3a63b327383a2ac1a8f925a58a2f6a7808f5181.tar.gz | |
libopkg: add option to strip ABI versions from listed names
Listing packages without the ABI versions appended to their names is
needed in some situations. Add a new command line option '--strip-abi'
for that which affects the 'list' and 'list-installed' command.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
| -rw-r--r-- | libopkg/opkg_cmd.c | 30 | ||||
| -rw-r--r-- | libopkg/opkg_conf.c | 1 | ||||
| -rw-r--r-- | libopkg/opkg_conf.h | 1 | ||||
| -rw-r--r-- | src/opkg-cl.c | 8 |
4 files changed, 38 insertions, 2 deletions
diff --git a/libopkg/opkg_cmd.c b/libopkg/opkg_cmd.c index 83e345e..7a9ee37 100644 --- a/libopkg/opkg_cmd.c +++ b/libopkg/opkg_cmd.c @@ -45,7 +45,23 @@ static void print_pkg(pkg_t * pkg) { char *version = pkg_version_str_alloc(pkg); char *description = pkg_get_string(pkg, PKG_DESCRIPTION); - printf("%s - %s", pkg->name, version); + const char *abiver; + char *tmp, *tmpname = NULL; + + if (conf->strip_abi && + (abiver = pkg_get_string(pkg, PKG_ABIVERSION)) && + (strlen(pkg->name) > strlen(abiver))) { + tmpname = strdup(pkg->name); + tmp = &tmpname[strlen(tmpname) - strlen(abiver)]; + if (!strncmp(abiver, tmp, strlen(abiver))) + *tmp = '\0'; + }; + + printf("%s - %s", tmpname?tmpname:pkg->name, version); + + if (tmpname) + free(tmpname); + if (conf->size) printf(" - %lu", (unsigned long) pkg_get_int(pkg, PKG_SIZE)); if (description) @@ -578,7 +594,8 @@ static void opkg_list_find_cmd_cb(pkg_t *pkg, void *priv) char *description = pkg_get_string(pkg, PKG_DESCRIPTION); char *version = pkg_version_str_alloc(pkg); struct opkg_list_find_cmd_item *item; - char *nameptr, *versionptr, *descriptionptr; + char *nameptr, *versionptr, *descriptionptr, *tmp; + const char *abiver; int i, found = 0; /* if we have package name or pattern and pkg does not match, then skip it */ @@ -603,6 +620,15 @@ static void opkg_list_find_cmd_cb(pkg_t *pkg, void *priv) &descriptionptr, description ? strlen(description) + 1 : 0); item->name = strcpy(nameptr, pkg->name); + + if (conf->strip_abi && + (abiver = pkg_get_string(pkg, PKG_ABIVERSION)) && + (strlen(item->name) > strlen(abiver))) { + tmp = &item->name[strlen(item->name) - strlen(abiver)]; + if (!strncmp(abiver, tmp, strlen(abiver))) + *tmp = '\0'; + }; + item->size = pkg_get_int(pkg, PKG_SIZE); item->version = strcpy(versionptr, version); item->description = description ? strcpy(descriptionptr, description) : NULL; diff --git a/libopkg/opkg_conf.c b/libopkg/opkg_conf.c index 5fe0be9..e36f66b 100644 --- a/libopkg/opkg_conf.c +++ b/libopkg/opkg_conf.c @@ -70,6 +70,7 @@ opkg_option_t options[] = { {"proxy_user", OPKG_OPT_TYPE_STRING, &_conf.proxy_user}, {"query-all", OPKG_OPT_TYPE_BOOL, &_conf.query_all}, {"size", OPKG_OPT_TYPE_BOOL, &_conf.size}, + {"strip_abi", OPKG_OPT_TYPE_BOOL, &_conf.strip_abi}, {"tmp_dir", OPKG_OPT_TYPE_STRING, &_conf.tmp_dir}, {"verbosity", OPKG_OPT_TYPE_INT, &_conf.verbosity}, {"verify_program", OPKG_OPT_TYPE_STRING, &_conf.verify_program}, diff --git a/libopkg/opkg_conf.h b/libopkg/opkg_conf.h index d38fd73..cd69ceb 100644 --- a/libopkg/opkg_conf.h +++ b/libopkg/opkg_conf.h @@ -89,6 +89,7 @@ struct opkg_conf { char *verify_program; int noaction; int size; + int strip_abi; int download_only; char *cache; diff --git a/src/opkg-cl.c b/src/opkg-cl.c index 01c6e94..793690d 100644 --- a/src/opkg-cl.c +++ b/src/opkg-cl.c @@ -55,6 +55,7 @@ enum { ARGS_OPT_NO_CHECK_CERTIFICATE, ARGS_OPT_VERIFY_PROGRAM, ARGS_OPT_SIZE, + ARGS_OPT_STRIP_ABI, }; static struct option long_options[] = { @@ -104,6 +105,8 @@ static struct option long_options[] = { {"add-arch", 1, 0, ARGS_OPT_ADD_ARCH}, {"add-dest", 1, 0, ARGS_OPT_ADD_DEST}, {"size", 0, 0, ARGS_OPT_SIZE}, + {"strip-abi", 0, 0, ARGS_OPT_STRIP_ABI}, + {"strip_abi", 0, 0, ARGS_OPT_STRIP_ABI}, {"test", 0, 0, ARGS_OPT_NOACTION}, {"tmp-dir", 1, 0, 't'}, {"tmp_dir", 1, 0, 't'}, @@ -238,6 +241,9 @@ static int args_parse(int argc, char *argv[]) case ARGS_OPT_VERIFY_PROGRAM: conf->verify_program = xstrdup(optarg); break; + case ARGS_OPT_STRIP_ABI: + conf->strip_abi = 1; + break; case ':': parse_err = -1; break; @@ -357,6 +363,8 @@ static void usage() ("\t--nocase Perform case insensitive pattern matching\n"); printf ("\t--size Print package size when listing available packages\n"); + printf + ("\t--strip-abi Print package name without appended ABI version\n"); printf("\t--force-removal-of-dependent-packages\n"); printf("\t Remove package and all dependencies\n"); printf("\t--autoremove Remove packages that were installed\n"); |