falconindy / expac

alpm data extraction utility
91 stars 15 forks source link

add versioned provisions support #32

Closed rmarquis closed 7 years ago

rmarquis commented 7 years ago

Consider the following:

$ sudo pacman -S "expac>7"
warning: expac-8-1 is up to date -- reinstalling
resolving dependencies...
looking for conflicting packages...

Package (1)  Old Version  New Version  Net Change  Download Size

extra/expac  8-1          8-1            0.00 MiB       0.01 MiB

Total Download Size:   0.01 MiB
Total Installed Size:  0.03 MiB
Net Upgrade Size:      0.00 MiB

:: Proceed with installation? [Y/n] n
$ sudo pacman -S "expac>8"
error: target not found: expac>8

Using expac:

$ expac -S '%r/%n-%v' expac
extra/expac-8-1
$ expac -S '%r/%n-%v' "expac>7"
(no result)

It would be useful to have a similar versining support in expac, as this might avoid the need to do some extra check separately before using expac. Hopefully this is in the scope of expac.

In my local fork, I've replaced alpm_db_get_pkg() with alpm_find_dbs_satisfier() when searching for exact packages, which gives the following results:

$ ./expac -Q '%r/%n-%v' "expac>8"
(no result, as expected)
$ ./expac -Q '%r/%n-%v' "expac>7"
local/expac-8-1
$ ./expac -S '%r/%n-%v' "expac>8"
(no result, as expected)
$ ./expac -S '%r/%n-%v' "expac>7"
extra/expac-8-1
extra/expac-8-1

It works, but for -S, the output is doubled - and I cannot find out the reason. Any idea?

I've tried passing r->next instead of r, but while the issue is fixed with -S, this breaks -Q.

falconindy commented 7 years ago

Even stranger for me...

./expac -S '%r/%n-%v' "expac>7"                                                                                                                                                                              
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 
extra/expac-8-1 

It seems to have something to do with the number of enabled repos which might indicate a bug in your patch somewhere.

Also, it's a shame that your patch makes "search_exact" not so exact anymore...

falconindy commented 7 years ago

Ah, I see. You want alpm_find_satisfier not alpm_dbs_find_satisfier.

$ ./expac -S '%r/%n-%v' "expac>7"
extra/expac-8-1

Ultimately, this would be a 1 line change.

diff --git a/expac.c b/expac.c
index d4d51fe..1222d0a 100644
--- a/expac.c
+++ b/expac.c
@@ -649,7 +649,7 @@ static alpm_list_t *search_exact(alpm_list_t *dblist, alpm_list_t *targets)
         continue;
       }

-      pkg = alpm_db_get_pkg(repo, pkgname);
+      pkg = alpm_find_satisfier(alpm_db_get_pkgcache(repo), pkgname);
       if(pkg == NULL) {
         continue;
       }

The real question is whether or not the semantics are appropriate.

rmarquis commented 7 years ago

Ah, thanks!

The real question is whether or not the semantics are appropriate.

I guess so. I always thought the behavior of expac was somewhat mimicking pacman, so I saw the above as a "missing feature". I might have been wrong here.

If you want to keep the behavior as strictly exact, maybe an optional flag would be appropriate? I'd consider that somewhat feature creep though, since I don't think the purpose of the original behavior has actually changed.

rmarquis commented 7 years ago

I'm closing this ticket - pacsift actually provides a similar feature, so no need to change semantics here.