-
Notifications
You must be signed in to change notification settings - Fork 395
Add rpm-sort utility for sorting RPM versions #2249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add rpm-sort utility for sorting RPM versions #2249
Conversation
2c21974
to
b2e6455
Compare
(CI was broken with 190354c, hence the revert commit.) |
I can see how grub* needs such a thing, but I don't really see why this should be in rpm itself. It's not a particularly common use-case AFAICS. |
I had to hand-roll something similar when figuring out which was the most recent VM kernel package I had installed in my dom0. |
Yeah there are use-cases, such as figuring out the order of stuff in a directory. Still, not convinced this needs to be in rpm. But assuming for a moment we were to merge this, there are some issues to sort (pun not intended) out:
|
rpmsort(8) is intended for use in shell scripts. sort(1) is not RPM versioning-aware, and attempting to work around that is fraught. Instead, provide a wrapper around rpmvercmp() using qsort(). Fedora's grub2 has carried a version of this since 2015, and a more complex version was also part of the grubby project (provided at /usr/libexec/grubby/rpm-sort) since 2018. This version has been simplified and adapted to the RPM project. Also-authored-by: Peter Jones <[email protected]> Signed-off-by: Peter Jones <[email protected]> Signed-off-by: Robbie Harwood <[email protected]>
b2e6455
to
b04fc4d
Compare
Thanks for the review; updated.
Well, depends on how you define "common", I suppose - it gets called every time a new kernel is installed, which is pretty common :)
I'm not seeing a better place for it - are you? It doesn't belong in grub or kernel-install because adding a build dependency on RPM doesn't make sense upstream. It doesn't belong in rpmdevtools because it needs to be installed on every system and that isn't. Pretty much all it does is provide a shell interface to a function from librpm. Looking at other systems for precendent, a tool like this generally isn't needed because |
Yes it happens a lot, in one highly specific corner. Which is often best served by having that specific corner handle it because it has its own wrinkles that do not apply elsewhere, like version comparing the name here. In principle, Debian versioning isn't that different from rpm. If 'sort -V' is good enough (if not perfect) for them then it should be close enough for government work for us too. Not that I have looked at the details, maybe the details differ more than it seems on the outset. Note that in rpm >= 4.16 you can also perform version comparisons from the cli with boolean expressions, eg
|
@frozencemetery Can you change |
It works accidentally. If I'd rather have an |
Could not quite bring myself to just say no. |
rpm-sort(8) is intended for use in shell scripts. sort(1) is not RPM versioning-aware, and attempting to work around that is fraught. Instead, provide a wrapper around rpmvercmp() using qsort().
Fedora's grub2 has carried a version of this since 2015, and a more complex version was also part of the grubby project (provided at /usr/libexec/grubby/rpm-sort) since 2018. This version has been simplified and adapted to the RPM project.
Also-authored-by: Peter Jones [email protected]
Signed-off-by: Peter Jones [email protected]
Signed-off-by: Robbie Harwood [email protected]
[Code is ready for inclusion.
While rpmdevtools does provide a rpmdev-vercmp utility, it is limited to comparing two versions at once only, meaning shell scripts would need to reimplement the sorting logic. It's also not typically installed on end-user systems, so we couldn't use it from grub2/grubby.]