[PATCH opkg] libopkg: pkg_hash: prefer original packages to satisfy dependencies
Matthias Schiffer
mschiffer at universe-factory.net
Wed Mar 17 15:08:19 GMT 2021
On 3/13/21 3:52 AM, Daniel Golle wrote:
> On Sat, Mar 13, 2021 at 02:00:40AM +0100, Matthias Schiffer wrote:
>> When one package "provides" another non-virtual package, prefer to use
>> the original package instead of the providing package.
>>
>> Example:
>>
>> Consider packages "foo" and "bar", where "foo" provides "bar".
>> The current code will sort all candidates by name and use the last entry
>> by default, so "foo" would be used to satisfy a dependency on "bar".
>> Change the logic to prefer the actual package "bar" in this case.
>>
>
> Reviewed-by: Daniel Golle <daniel at makrotopia.org>
>
>> Signed-off-by: Matthias Schiffer <mschiffer at universe-factory.net>
>> ---
>> libopkg/pkg_hash.c | 14 ++++++++++++--
>> 1 file changed, 12 insertions(+), 2 deletions(-)
>>
>> diff --git a/libopkg/pkg_hash.c b/libopkg/pkg_hash.c
>> index dbed3febfbbe..a07a25ec1e0b 100644
>> --- a/libopkg/pkg_hash.c
>> +++ b/libopkg/pkg_hash.c
>> @@ -284,6 +284,7 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
>> int nmatching = 0;
>> int wrong_arch_found = 0;
>> int arch_priority;
>> + int good_pkg_score = 0;
>> pkg_vec_t *matching_pkgs;
>> abstract_pkg_vec_t *matching_apkgs;
>> abstract_pkg_vec_t *provided_apkg_vec;
>> @@ -409,9 +410,18 @@ pkg_t *pkg_hash_fetch_best_installation_candidate(abstract_pkg_t * apkg,
>> for (i = 0; i < matching_pkgs->len; i++) {
>> pkg_t *matching = matching_pkgs->pkgs[i];
>> if (constraint_fcn(matching, cdata)) {
>> - opkg_msg(DEBUG, "Candidate: %s %s.\n",
>> - matching->name, pkg_get_string(matching, PKG_VERSION));
>> + int score = 1;
>> + if (strcmp(matching->name, apkg->name) == 0)
>> + score++;
>
> ++score;
>
> As you are not using the return value, no need for post-increment.
> The compiler should be able to recognize and optmize that away by now
> though, so probably it doesn't matter.
The difference is only meaningful in C++, where preincrement and
postincrement may use different operator overloads. In C, I prefer the
postincrement when I don't need the result, simply for aesthetic reasons ;)
>
>> +
>> + opkg_msg(DEBUG, "Candidate: %s %s (score %d).\n",
>> + matching->name, pkg_get_string(matching, PKG_VERSION),
>> + score);
>> + if (score < good_pkg_score)
>> + continue;
>> +
>> good_pkg_by_name = matching;
>> + good_pkg_score = score;
>> /* It has been provided by hand, so it is what user want */
>> if (matching->provided_by_hand == 1)
>> break;
>> --
>> 2.30.2
>>
>>
>> _______________________________________________
>> openwrt-devel mailing list
>> openwrt-devel at lists.openwrt.org
>> https://lists.openwrt.org/mailman/listinfo/openwrt-devel
-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <http://lists.openwrt.org/pipermail/openwrt-devel/attachments/20210317/048b04ec/attachment.sig>
More information about the openwrt-devel
mailing list