libopkg: pkg_hash: prefer to-be-installed packages
authorDaniel Golle <daniel@makrotopia.org>
Sun, 9 Jan 2022 19:52:40 +0000 (19:52 +0000)
committerDaniel Golle <daniel@makrotopia.org>
Sun, 9 Jan 2022 19:59:00 +0000 (19:59 +0000)
Increase PROVIDES candidate score also in case the package name matches
a to-be-installed package listed.

Signed-off-by: Daniel Golle <daniel@makrotopia.org>
libopkg/opkg_cmd.c
libopkg/opkg_cmd.h
libopkg/pkg_hash.c

index 7a9ee37006e64e77d3f2799cfef02d9d861c9965..b6c45f523cdd06277cb35c87eef7100046c2c5a7 100644 (file)
@@ -41,6 +41,9 @@
 #include "opkg_configure.h"
 #include "xsystem.h"
 
+int opkg_cli_argc = 0;
+char **opkg_cli_argv = NULL;
+
 static void print_pkg(pkg_t * pkg)
 {
        char *version = pkg_version_str_alloc(pkg);
@@ -1427,5 +1430,7 @@ opkg_cmd_t *opkg_cmd_find(const char *name)
 
 int opkg_cmd_exec(opkg_cmd_t * cmd, int argc, const char **argv)
 {
+       opkg_cli_argc = argc;
+       opkg_cli_argv = argv;
        return (cmd->fun) (argc, argv);
 }
index e23d773aec804a5ec4cdd20e9a95880a653c9ca3..8831bd367c5881056fd114a43557e7b76a8fae41 100644 (file)
@@ -32,4 +32,6 @@ opkg_cmd_t *opkg_cmd_find(const char *name);
 int opkg_cmd_exec(opkg_cmd_t * cmd, int argc, const char **argv);
 
 extern int opkg_state_changed;
+extern int opkg_cli_argc;
+extern char **opkg_cli_argv;
 #endif
index c58703f60e663de224b93aabaa61901cd841e560..11b1a06bc83c759efe37c500c0212a3fd20ad8c8 100644 (file)
@@ -26,6 +26,7 @@
 #include "parse_util.h"
 #include "pkg_parse.h"
 #include "opkg_utils.h"
+#include "opkg_cmd.h"
 #include "sprintf_alloc.h"
 #include "file_util.h"
 #include "libbb/libbb.h"
@@ -416,6 +417,13 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
                        if (strcmp(matching->name, apkg->name) == 0)
                                score++;
 
+                       for (j = 0; j < opkg_cli_argc; ++j) {
+                               if (!strcmp(matching->name, opkg_cli_argv[j])) {
+                                       score++;
+                                       break;
+                               }
+                       }
+
                        opkg_msg(DEBUG, "Candidate: %s %s (score %d).\n",
                                 matching->name, pkg_get_string(matching, PKG_VERSION),
                                 score);