aboutsummaryrefslogtreecommitdiffstats
path: root/genfilelist
diff options
context:
space:
mode:
authorFrancois Pons <fpons@mandriva.com>2000-04-04 13:08:17 +0000
committerFrancois Pons <fpons@mandriva.com>2000-04-04 13:08:17 +0000
commitf5555f119ebbdcc438480d4ef5b2af1a20038594 (patch)
tree97f7988f656af4351a495a05da31cb30b0acc680 /genfilelist
parent35985dc620eb38a6f7f028617cea43d48268a777 (diff)
downloadrpmtools-f5555f119ebbdcc438480d4ef5b2af1a20038594.tar
rpmtools-f5555f119ebbdcc438480d4ef5b2af1a20038594.tar.gz
rpmtools-f5555f119ebbdcc438480d4ef5b2af1a20038594.tar.bz2
rpmtools-f5555f119ebbdcc438480d4ef5b2af1a20038594.tar.xz
rpmtools-f5555f119ebbdcc438480d4ef5b2af1a20038594.zip
*** empty log message ***
Diffstat (limited to 'genfilelist')
-rwxr-xr-xgenfilelist91
1 files changed, 48 insertions, 43 deletions
diff --git a/genfilelist b/genfilelist
index b7e8c77..fa4d1dd 100755
--- a/genfilelist
+++ b/genfilelist
@@ -30,44 +30,39 @@ sub packfilelist {
#- search for common parts of name.
foreach (@_) {
my $filename = $_;
- foreach (0..length($filename)) {
+ foreach (4..length($filename)) {
++$countdir{substr($filename, 0, $_)};
}
}
+ my @costlysort = (sort { $countdir{$b} <=> $countdir{$a} || ($countdir{$b} == $countdir{$a} && length($b) <=> length($a)) }
+ grep { $countdir{$_} > 2 }
+ keys %countdir);
+
#- pass 1: recompute counter.
- foreach (sort { $countdir{$b} <=> $countdir{$a} || ($countdir{$b} == $countdir{$a} && length($b) <=> length($a)) }
- keys %countdir) {
+ foreach (grep { length($_) > 4 } @costlysort) {
my $filepart = $_;
- if (length($filepart) > 4 && $countdir{$filepart} > 1) {
- foreach (0..length($filepart)-1) {
- my $subpart = substr($filepart, 0, $_);
- if (length($subpart) * $countdir{$subpart} < length($filepart) * $countdir{$filepart}) {
- $countdir{$subpart} -= $countdir{$filepart} if $countdir{$filepart} > 0;
- } else {
- $countdir{$filepart} -= $countdir{$subpart} if $countdir{$subpart} > 0;
- }
+ foreach (4..length($filepart)-1) {
+ my $subpart = substr($filepart, 0, $_);
+ if (length($subpart) * $countdir{$subpart} < length($filepart) * $countdir{$filepart}) {
+ $countdir{$subpart} -= $countdir{$filepart} if $countdir{$filepart} > 0;
+ } else {
+ $countdir{$filepart} -= $countdir{$subpart} if $countdir{$subpart} > 0;
}
- } else {
- delete $countdir{$filepart};
}
}
#- pass 2: filter out overstring.
- foreach (sort { $countdir{$a} <=> $countdir{$b} || ($countdir{$a} == $countdir{$b} && length($a) <=> length($b)) }
- keys %countdir) {
+ foreach (grep { length($_) > 4 && $countdir{$_} > 2 } reverse @costlysort) {
my $filepart = $_;
- if ($countdir{$filepart} > 1) {
- foreach (0..length($filepart)-1) {
- delete $countdir{substr($filepart, 0, $_)};
- }
+ foreach (4..length($filepart)-1) {
+ delete $countdir{substr($filepart, 0, $_)};
}
}
#- pass 3: get result.
- foreach (sort { $countdir{$b} <=> $countdir{$a} || ($countdir{$b} == $countdir{$a} && length($b) <=> length($a)) }
- keys %countdir) {
- push @commonparts, $_ if $countdir{$_} > 1 && @commonparts < 10;
+ foreach (grep { $countdir{$_} > 2 } @costlysort) {
+ push @commonparts, $_ if @commonparts < 10;
}
@commonparts;
@@ -76,30 +71,40 @@ sub packfilelist {
#- main program.
sub main {
my ($rpms_dir) = @_;
+ my (@filelist, @obsoletes) = ();
- local *DIR;
- opendir DIR, $rpms_dir or die "unable to parse directory: $!";
- foreach (readdir DIR) {
- if (/(.*)-[^-]*-[^-]*$/) {
- print "#$1\n";
-
- my @filelist = split '\n', `rpm -qpl $rpms_dir/$_`;
- my @obsoletes = split '\n', `rpm -qp --obsoletes $rpms_dir/$_`;
- my @commonparts = packfilelist(@filelist);
-
- foreach (@obsoletes) { print "*$_\n" }
- foreach (0..$#commonparts) { print "=$commonparts[$_]\n" } #- commonparts are printed in from 0 to n-1.
- foreach my $filename (@filelist) {
- map {
- if (substr($filename, 0, length($commonparts[$_])) eq $commonparts[$_]) {
- print $_ . substr($filename, length($commonparts[$_])) . "\n"; next;
- }
- } (0..$#commonparts);
- print " $filename\n";
- }
+ local *RPM_QA;
+ open RPM_QA, "rpm -qp --queryformat \"#\%{NAME}\\n\" --obsoletes -l $rpms_dir/*.rpm |";
+ foreach (<RPM_QA>) {
+ if (/^\#/) {
+ #- work on previous obsoletes and filelist.
+ genfilelist(\@filelist, \@obsoletes);
+
+ (@filelist, @obsoletes) = ();
+
+ print $_;
+ } else {
+ chomp;
+ m|^/| ? push(@filelist, $_) : push(@obsoletes, $_);
}
}
- closedir DIR;
+ genfilelist(\@filelist, \@obsoletes);
+}
+
+sub genfilelist {
+ my ($filelist, $obsoletes) = @_;
+ my @commonparts = packfilelist(@$filelist);
+
+ foreach (@$obsoletes) { print "*$_\n" }
+ foreach (@commonparts) { print "=$_\n" } #- commonparts are printed in from 0 to n-1.
+ foreach my $filename (@$filelist) {
+ map {
+ if (substr($filename, 0, length($commonparts[$_])) eq $commonparts[$_]) {
+ print $_ . substr($filename, length($commonparts[$_])) . "\n"; next;
+ }
+ } (0..$#commonparts);
+ print " $filename\n";
+ }
}
foreach (@ARGV) {