[pve-devel] [RFC manager] pveversion: sort kernel packages by version

Fabian Grünbichler f.gruenbichler at proxmox.com
Thu Feb 15 14:13:20 CET 2018


instead of lexically by package name

Signed-off-by: Fabian Grünbichler <f.gruenbichler at proxmox.com>
---
note: might be made more elegant with some perl wizardry? ;)

instead of:

pve-kernel-4.10.17-3-pve: 4.10.17-23
pve-kernel-4.10.17-4-pve: 4.10.17-24
pve-kernel-4.10.17-5-pve: 4.10.17-25
pve-kernel-4.13.1-1-pve: 4.13.1-1
pve-kernel-4.13.13-1-pve: 4.13.13-31
pve-kernel-4.13.13-2-pve: 4.13.13-33
pve-kernel-4.13.13-3-pve: 4.13.13-34
pve-kernel-4.13.13-4-pve: 4.13.13-35
pve-kernel-4.13.13-5-pve: 4.13.13-38
pve-kernel-4.13.13-6-pve: 4.13.13-39
pve-kernel-4.13.3-1-pve: 4.13.3-2
pve-kernel-4.13.4-1-pve: 4.13.4-26
pve-kernel-4.13.8-1-pve: 4.13.8-27
pve-kernel-4.13.8-2-pve: 4.13.8-28
pve-kernel-4.13.8-3-pve: 4.13.8-30

we now get:

pve-kernel-4.13.13-6-pve: 4.13.13-39
pve-kernel-4.13.13-5-pve: 4.13.13-38
pve-kernel-4.13.13-4-pve: 4.13.13-35
pve-kernel-4.13.13-3-pve: 4.13.13-34
pve-kernel-4.13.13-2-pve: 4.13.13-33
pve-kernel-4.13.13-1-pve: 4.13.13-31
pve-kernel-4.13.8-3-pve: 4.13.8-30
pve-kernel-4.13.8-2-pve: 4.13.8-28
pve-kernel-4.13.8-1-pve: 4.13.8-27
pve-kernel-4.13.4-1-pve: 4.13.4-26
pve-kernel-4.13.3-1-pve: 4.13.3-2
pve-kernel-4.13.1-1-pve: 4.13.1-1
pve-kernel-4.10.17-5-pve: 4.10.17-25
pve-kernel-4.10.17-4-pve: 4.10.17-24
pve-kernel-4.10.17-3-pve: 4.10.17-23

 PVE/API2/APT.pm | 7 +++++--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/PVE/API2/APT.pm b/PVE/API2/APT.pm
index d0e3d4bd..1988b3aa 100644
--- a/PVE/API2/APT.pm
+++ b/PVE/API2/APT.pm
@@ -24,8 +24,8 @@ use JSON;
 use PVE::JSONSchema qw(get_standard_option);
 
 use AptPkg::Cache;
-use AptPkg::Version;
 use AptPkg::PkgRecords;
+use Dpkg::Version;
 
 my $get_apt_cache = sub {
     
@@ -521,7 +521,10 @@ __PACKAGE__->register_method({
 	# order most important things first
 	my @list = qw(proxmox-ve pve-manager);
 
-	push @list, grep { /^pve-kernel-/ && $cache->{$_}->{CurrentState} eq 'Installed' } sort keys %$cache;
+	push @list, sort {
+	    Dpkg::Version::version_compare($cache->{$b}->{CurrentVer}->{VerStr},
+	                                   $cache->{$a}->{CurrentVer}->{VerStr});
+	    } grep { /^pve-kernel-/ && $cache->{$_}->{CurrentState} eq 'Installed' } sort keys %$cache;
 
         my @opt_pack = qw(
 	    ceph
-- 
2.14.2





More information about the pve-devel mailing list