-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathlist-older-rpm.pl
executable file
·61 lines (52 loc) · 1.47 KB
/
list-older-rpm.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/usr/bin/perl -w
use strict;
sub usage {
die <<END;
Usage: $0 *.rpm
Compares given rpms w.r.t VERSION/RELEASE and list up older (obsoleted) ones.
END
}
@ARGV or usage();
my $format = <<'END';
%{NAME}\t%{VERSION}\t%{RELEASE}\t%{NAME}-%{VERSION}-%{RELEASE}.%{ARCH}.rpm
END
open PIPE, '-|' or exec "rpm", "-qp", "--qf" => $format, @ARGV;
use constant VERSION => 0;
use constant RELEASE => 1;
use constant FILE => 2;
sub vercomp {
my (@a) = split /(\D+)/, $_[0];
my (@b) = split /(\D+)/, $_[1];
my $state;
for (my $i = 0; $i < @a and $i < @b;) {
# even
return $state unless ($state = ($a[$i]||0) <=> ($b[$i]||0)) == 0;
$i++; last unless $i < @a and $i < @b;
# odd
return $state unless ($state = $a[$i] cmp $b[$i]) == 0;
$i++;
}
@a <=> @b;
}
my %dict;
while (<PIPE>) {
chomp;
my ($name, $version, $release, $file) = split /\t/, $_, 4;
if (not defined $dict{$name}) {
$dict{$name} = [$version, $release, $file];
} else {
printf "version(%s) %s %s\n", $name, $dict{$name}->[VERSION], $version
if $ENV{VERBOSE};
if (vercomp($dict{$name}->[VERSION], $version) < 0) {
print $dict{$name}->[FILE], "\n";
$dict{$name} = [$version, $release, $file];
next;
}
printf "release(%s) %s %s\n", $name, $dict{$name}->[RELEASE], $release
if $ENV{VERBOSE};
if (vercomp($dict{$name}->[RELEASE], $release) <= 0) {
print $dict{$name}->[FILE], "\n";
$dict{$name} = [$version, $release, $file];
}
}
}