From ba785a886ccbfb71d6ad84d0c615479939a0c62f Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Thu, 6 Dec 2007 00:13:01 +0100 Subject: [PATCH] parse-contents: Code clean-up use English use Packages::CommonCode whitespace clean-up and some other style fixes --- bin/parse-contents | 59 +++++++++++++++++++++++++--------------------- 1 file changed, 32 insertions(+), 27 deletions(-) diff --git a/bin/parse-contents b/bin/parse-contents index ef5c09c..c254375 100755 --- a/bin/parse-contents +++ b/bin/parse-contents @@ -34,9 +34,11 @@ my $what = $ARGV[0] ? "head -10000|" : ""; # temporary files, and is adviced when possible my $SORT_REVERSE_CONCURRENTLY = 1; +use English; use DB_File; use Storable; use File::Path; +use Packages::CommonCode qw(:all); use Packages::Config qw( $TOPDIR $DBDIR @ARCHIVES @SUITES @ARCHITECTURES ); &Packages::Config::init( './' ); @@ -45,7 +47,7 @@ my @suites = @SUITES; my @archs = @ARCHITECTURES; $DBDIR .= "/contents"; --d $DBDIR || mkpath( $DBDIR ); +mkdirp( $DBDIR ); for my $suite (@suites) { for my $arch (@archs) { @@ -55,15 +57,15 @@ for my $suite (@suites) { my %packages_contents = (); my %packages_contents_nr = (); my %packages_contents_lastword = (); - + my $extra = ""; $extra = "|sort" if $SORT_REVERSE_CONCURRENTLY; - + open REVERSED, "$extra>$DBDIR/reverse.tmp" or die "Failed to open output reverse file: $!"; my $changed = 0; - for my $archive (@archives) { + for my $archive (@archives) { my $filename = "$TOPDIR/archive/$archive/$suite/Contents-$arch.gz"; next unless -f $filename; @@ -74,12 +76,12 @@ for my $suite (@suites) { $changed++; } if ($changed) { - for my $archive (@archives) { + for my $archive (@archives) { my $filename = "$TOPDIR/archive/$archive/$suite/Contents-$arch.gz"; next unless -f $filename; print "Reading $archive/$suite/$arch...\n"; - + open CONT, "zcat $filename|$what" or die $!; while () { last if /^FILE/mo; } @@ -91,11 +93,12 @@ for my $suite (@suites) { my $data = ""; my %data = (); chomp; - print "Doing line ".($./1000)."k (out of approx 2.0M)\n" if $. % 250000 == 0; + print "Doing line ".($NR/1000)."k (out of approx 2.0M)\n" + if $NR % 250000 == 0; /^(.+?)\s+(\S+)$/o; my ($file, $value) = ($1, $2); $value =~ s#[^,/]+/##og; - my @packages = split /,/, $value; + my @packages = split m/,/, $value; for (@packages) { $packages_contents_nr{$_}++; my $lw = $packages_contents_lastword{$_} || "\0"; @@ -114,15 +117,16 @@ for my $suite (@suites) { (join ":$arch\0", @packages).":$arch\n"; } close CONT; - + } close REVERSED; - + print "Sorting reverse list if needed\n"; - system("cd $DBDIR && sort reverse.tmp > reverse.sorted && mv reverse.{sorted,tmp}") == 0 - or die "Failed to sort reverse" - unless $SORT_REVERSE_CONCURRENTLY; - + system("cd $DBDIR && sort reverse.tmp > reverse.sorted &&". + " mv reverse.{sorted,tmp}") == 0 + or die "Failed to sort reverse" + unless $SORT_REVERSE_CONCURRENTLY; + print "Writing filelist db\n"; tie my %packages_contents_db, "DB_File", "$filelist_db.new", O_RDWR|O_CREAT, 0666, $DB_BTREE @@ -132,15 +136,16 @@ for my $suite (@suites) { . $v; } untie %packages_contents_db; - + 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 - or die "Oops"; + + activate($filelist_db); + system("ln", "-sf", $filelist_db, + "$DBDIR/filelists_${suite}_all.db") == 0 + or die "Oops"; } } - + my $go = 0; my $suite_mtime = (stat "$DBDIR/reverse_$suite.db")[9]; for my $file (glob "$DBDIR/reverse_${suite}_*.txt") { @@ -156,16 +161,16 @@ for my $suite (@suites) { 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 + O_RDWR|O_CREAT, 0666, $DB_BTREE or die "Error creating DB: $!"; my $lastpath = my $lastcasepath = my $lastfile = ""; my %matches = (); while () { - print "Doing line ".($./1000000)."M (out of approx. 20M)\n" - if $. % 1000000 == 0; + print "Doing line ".($NR/1000000)."M (out of approx. 20M)\n" + if $NR % 1000000 == 0; chomp; - my @line = split /\0/o, $_; + my @line = split m/\0/o, $_; my $revpath = shift @line; my $casepath = shift @line; if ($revpath ne $lastpath) { @@ -206,9 +211,9 @@ for my $suite (@suites) { untie %reverse_path_db; close FILENAMES; close MERGED; - - rename "$DBDIR/filenames_$suite.txt.new", "$DBDIR/filenames_$suite.txt"; - rename "$DBDIR/reverse_$suite.db.new", "$DBDIR/reverse_$suite.db"; + + activate("$DBDIR/filenames_$suite.txt"); + activate("$DBDIR/reverse_$suite.db"); } # vim: set ts=4 -- 2.39.2