From a8785e7b7237c8a9789f40c21ae262622d56d075 Mon Sep 17 00:00:00 2001 From: Rob Vermaas Date: Tue, 27 Dec 2011 12:56:07 +0000 Subject: [PATCH] use simple version compare in stead of timestamps to determine newer package svn path=/nixpkgs/trunk/; revision=31108 --- pkgs/build-support/vm/rpm/rpm-closure.pl | 42 +++++++++++++++++++++++- 1 file changed, 41 insertions(+), 1 deletion(-) diff --git a/pkgs/build-support/vm/rpm/rpm-closure.pl b/pkgs/build-support/vm/rpm/rpm-closure.pl index 5efc162784ac..2ef59dcbdef3 100644 --- a/pkgs/build-support/vm/rpm/rpm-closure.pl +++ b/pkgs/build-support/vm/rpm/rpm-closure.pl @@ -1,5 +1,6 @@ use strict; use XML::Simple; +use List::Util qw(min); my @packagesFiles = (); my @urlPrefixes = (); @@ -13,6 +14,44 @@ while(-f $ARGV[0]) { push(@urlPrefixes, $urlPrefix); } + +sub rpmvercmp { + my ($version1, $version2) = @_; + my @vercmps1 = split /\./, $version1; + my @vercmps2 = split /\./, $version2; + my $l1 = scalar(@vercmps1); + my $l2 = scalar(@vercmps2); + my $l = min($l1, $l2); + + for(my $i=0; $i<$l; $i++) { + my $v1 = $vercmps1[$i]; + my $v2 = $vercmps2[$i]; + + if($v1 =~ /^[0-9]*$/ && $v2 =~ /^[0-9]*$/) { + if ( int($v1) > int($v2) ) { + return 1; + } + elsif ( int($v1) < int($v2) ) { + return -1; + } + } else { + if ( $v1 gt $v2 ) { + return 1; + } + elsif ( $v1 lt $v2 ) { + return -1; + } + } + } + if($l1 == $l2) { + return 0; + } elsif ($l1 > $l2) { + return 1; + } elsif ($l1 < $l2) { + return -1; + } +} + my @toplevelPkgs = @ARGV; my @archs = split ' ', ($ENV{'archs'} or ""); @@ -36,7 +75,8 @@ for (my $i = 0; $i < scalar(@packagesFiles); $i++) { if (defined $pkgs{$pkg->{name}}) { my $earlierPkg = $pkgs{$pkg->{name}}; print STDERR "WARNING: duplicate occurrence of package $pkg->{name}\n"; - if ($earlierPkg->{'time'}->{file} <= $pkg->{'time'}->{file}) { + # + if (rpmvercmp($pkg->{'version'}->{ver}, $earlierPkg->{'version'}->{ver}) >= 0) { print STDERR "WARNING: replaced package $pkg->{name} with newer one\n"; $pkg->{urlPrefix} = $urlPrefixes[$i]; $pkgs{$pkg->{name}} = $pkg;