X-Git-Url: https://git.deb.at/?p=deb%2Fpackages.git;a=blobdiff_plain;f=bin%2Fparse-contents;h=ef5c09ce2b4645395371392f5f3a732dd913cae6;hp=36c90b1479fd54e937d80c21601e94dcd1f87532;hb=f7b85516f73e6a06d309e42be07c9f3def2877b5;hpb=d833a5eed5296d1a24c35e8f0802f8291037198d diff --git a/bin/parse-contents b/bin/parse-contents index 36c90b1..ef5c09c 100755 --- a/bin/parse-contents +++ b/bin/parse-contents @@ -18,6 +18,7 @@ # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. use strict; +use warnings; use lib './lib'; $| = 1; @@ -81,13 +82,16 @@ for my $suite (@suites) { open CONT, "zcat $filename|$what" or die $!; - while () {last if /^FILE/mo;} - open CONT, "zcat $filename|$what" if eof(CONT); + while () { last if /^FILE/mo; } + if (eof(CONT)) { # no header found + close CONT; # explicit close to reset $. + open CONT, "zcat $filename|$what"; + } while () { my $data = ""; my %data = (); chomp; - print "Doing line ".($./1000)."k (out of approx 1.5M)\n" if $. % 250000 == 0; + print "Doing line ".($./1000)."k (out of approx 2.0M)\n" if $. % 250000 == 0; /^(.+?)\s+(\S+)$/o; my ($file, $value) = ($1, $2); $value =~ s#[^,/]+/##og; @@ -103,9 +107,11 @@ for my $suite (@suites) { $packages_contents_lastword{$_} = "$file\0"; } # Searches are case-insensitive - $file =~ tr [A-Z] [a-z]; - - print REVERSED (reverse $file)."\0".(join ":$arch\0", @packages).":$arch\n"; + (my $nocase = $file) =~ tr [A-Z] [a-z]; + my $case = ($nocase eq $file) ? '-' : $file; + + print REVERSED (reverse $nocase)."\0".$case."\0". + (join ":$arch\0", @packages).":$arch\n"; } close CONT; @@ -130,7 +136,7 @@ for my $suite (@suites) { rename("$DBDIR/reverse.tmp", "$DBDIR/reverse_${suite}_${arch}.txt"); rename("$filelist_db.new", $filelist_db); - system("ln -sf $filelist_db $DBDIR/filelists_${suite}_all.db") == 0 + system("ln", "-sf", $filelist_db, "$DBDIR/filelists_${suite}_all.db") == 0 or die "Oops"; } } @@ -145,26 +151,33 @@ for my $suite (@suites) { print "Merging reverse path lists for ${suite}...\n"; - open MERGED, "sort -m $DBDIR/reverse_${suite}_*.txt |" + open MERGED, "-|", "sort -m $DBDIR/reverse_${suite}_*.txt" or die "Failed to open merged list"; - open FILENAMES, "> $DBDIR/filenames_$suite.txt.new" + open FILENAMES, ">", "$DBDIR/filenames_$suite.txt.new" or die "Failed to open filenames list"; tie my %reverse_path_db, "DB_File", "$DBDIR/reverse_${suite}.db.new", O_RDWR|O_CREAT, 0666, $DB_BTREE or die "Error creating DB: $!"; - my $lastpath = ""; - my $lastfile = ""; - my @matches = (); + my $lastpath = my $lastcasepath = my $lastfile = ""; + my %matches = (); while () { - print "Doing line ".($./1000000)."M (out of approx. 16M)\n" + print "Doing line ".($./1000000)."M (out of approx. 20M)\n" if $. % 1000000 == 0; chomp; my @line = split /\0/o, $_; my $revpath = shift @line; + my $casepath = shift @line; if ($revpath ne $lastpath) { # Wrap: Do useful stuff with this ($lastpath, @matches) - $reverse_path_db{$lastpath} = join "\0", @matches if $lastpath ne ""; + if ($lastpath ne "") { + my @matches; + while (my ($k, $v) = each %matches) { + push @matches, join("\0", $k, @$v); + } + $reverse_path_db{$lastpath} = join "\1", @matches; + %matches = (); + } $lastpath =~ s,/.*,,o; if ($lastfile ne $lastpath) { $lastfile = $lastpath; @@ -172,15 +185,24 @@ for my $suite (@suites) { } # $lastpath = $revpath; - @matches = @line; + $lastcasepath = $casepath; + $matches{$casepath} = \@line; next; +# } elsif ($lastcasepath ne "" and $casepath ne $lastcasepath) { +# warn reverse($revpath)." has more than one casepath: $casepath $lastcasepath\n"; } - push @matches, @line - } + push @{$matches{$casepath}}, @line; + } # Note: do useful stuff here too, for out last entry. Maybe prevent this by # adding a fake ultimate entry? - $reverse_path_db{$lastpath} = join "\0", @matches; - + { + my @matches; + while (my ($k, $v) = each %matches) { + push @matches, join("\0", $k, @$v); + } + $reverse_path_db{$lastpath} = join "\1", @matches; + } + untie %reverse_path_db; close FILENAMES; close MERGED;