From 3b39a05cdd95fd98b08fc74ec1463f8def465457 Mon Sep 17 00:00:00 2001 From: Frank Lichtenheld Date: Fri, 19 Oct 2007 23:32:18 +0200 Subject: [PATCH] Rework newpkg stuff Create lists for all suites, not just sid (this also avoids having to hardcode the suite name, which is nicer for the Ubuntu archive). Handle packages correctly that get added and immediatly deleted or deleted and immediatly readded. Not that I would have some examples for that but it might happen. --- bin/newpkg_info | 81 ++++++++++++++++++++++++++-------------- cron.d/600prepare_newpkg | 20 ++++++---- lib/Packages/DoNewPkg.pm | 12 ++++-- 3 files changed, 73 insertions(+), 40 deletions(-) diff --git a/bin/newpkg_info b/bin/newpkg_info index 37b7290..b55b45d 100755 --- a/bin/newpkg_info +++ b/bin/newpkg_info @@ -13,6 +13,7 @@ use Packages::Search qw( :all ); my $suite = $ARGV[0] or die "Fatal Error: No suite given"; my $start_time = time; +my $debug = 1; tie my %packages, 'DB_File', "$DBDIR/packages_small.db", O_RDONLY, 0666, $DB_BTREE @@ -27,22 +28,30 @@ sub get_iso_date { return sprintf( "%04s-%02s-%02s", $year, $month, $day ); } -open CHANGES, '>', "$TOPDIR/files/packages/newpkg_info.new" +my $packagesdir = "$TOPDIR/files/packages"; +open CHANGES, '>', "$packagesdir/newpkg_info_$suite.new" or die "Fatal Error: Couldn't open CHANGES file: $!"; -for (my $age = 0; $age < 7; $age++) { - my (%old, %changes); +my (%add, %del); +my $lastday; +for (my $age = 7; $age >= 0; $age--) { + my (%old); my $newday = get_iso_date( $age ); my $oldday = get_iso_date( $age+1 ); - open OLD, '<', "$TOPDIR/files/packages/package_names_$suite.$oldday" - or do { - warn "Warning: Couldn't open OLD file $TOPDIR/files/packages/package_names_$suite.$oldday: $!\n"; - next; - }; - open NEW, '<', "$TOPDIR/files/packages/package_names_$suite.$newday" - or do { - warn "Warning: Couldn't open NEW file $TOPDIR/files/packages/package_names_$suite.$newday: $!\n"; - next; - }; + -d "$packagesdir/$oldday" or do { + warn "Warning: No information available for $oldday\n"; + next unless $lastday; + $oldday = $lastday; + }; + -d "$packagesdir/$newday" or do { + warn "Warning: No information available for $newday\n"; + next; + }; + $lastday = $newday; + warn "Process: age=$age oldday=$oldday newday=$newday\n" if $debug; + open OLD, '<', "$packagesdir/$oldday/package_names_$suite" + or die "Error: Couldn't open OLD file $packagesdir/$oldday/package_names_$suite: $!\n"; + open NEW, '<', "$packagesdir/$newday/package_names_$suite" + or die "Error: Couldn't open NEW file $packagesdir/$newday/package_names_$suite: $!\n"; while () { chomp; $old{$_} = 1; @@ -54,28 +63,44 @@ for (my $age = 0; $age < 7; $age++) { # we assume here that the input contains no dupes! delete $old{$_}; } else { - $changes{$_} = 1; + if (exists $del{$_}) { + delete $del{$_}; + warn "Re-Added: $_\n" if $debug; + } else { + $add{$_} = $age; + warn "Added: $_ (age $age)\n" if $debug; + } } } close NEW; foreach (keys %old) { - $changes{$_} = -1; + if (exists $add{$_}) { + delete $add{$_}; + warn "Deleted again: $_\n" if $debug; + } else { + $del{$_} = $age; + warn "Deleted: $_ (age $age)\n" if $debug; + } } - my %archives = map { $_ => 1 } qw( us security ); - foreach (sort keys %changes) { - my $entry = []; - if ($changes{$_} == 1) { - $entry = read_entry_simple( \%packages, $_, \%archives, $suite); - die "Fatal Error: Can't find entry for package $_\n" - unless @$entry; - shift @$entry; # remove virtual pkg info - } - print CHANGES join(" ", $_, $age, @$entry)."\n"; - print "Wrote entry: ".join(" ", $_, $age, @$entry)."\n"; +} +my %archives = map { $_ => 1 } qw( us security ); +foreach (sort (keys %add, keys %del)) { + my $entry = []; + my $age = 0; + if (exists $add{$_}) { + $entry = read_entry_simple( \%packages, $_, \%archives, $suite); + die "Fatal Error: Can't find entry for package $_\n" + unless @$entry; + shift @$entry; # remove virtual pkg info + $age = $add{$_}; + } else { + $age = $del{$_}; } + print CHANGES join(" ", $_, $age, @$entry)."\n"; + print "Wrote entry: ".join(" ", $_, $age, @$entry)."\n"; } close CHANGES; -rename("$TOPDIR/files/packages/newpkg_info.new", - "$TOPDIR/files/packages/newpkg_info"); +rename("$packagesdir/newpkg_info_$suite.new", + "$packagesdir/newpkg_info_$suite"); diff --git a/cron.d/600prepare_newpkg b/cron.d/600prepare_newpkg index f722cb2..23cd8b8 100755 --- a/cron.d/600prepare_newpkg +++ b/cron.d/600prepare_newpkg @@ -2,14 +2,18 @@ . `dirname $0`/../config.sh -packagesdir=${filesdir}/packages -test -d ${packagesdir} || mkdir -p ${packagesdir} - -LANG=C cat ${filesdir}/db/package_names_sid.txt \ - | sort | uniq > ${packagesdir}/package_names_sid.$(date -I) -LANG=C cat ${filesdir}/db/source_names_sid.txt \ - | sort | uniq > ${packagesdir}/source_names_sid.$(date -I) +isodate=$(date -I) +packagesdir="${filesdir}/packages/${isodate}" +test -d "${packagesdir}" || mkdir -p "${packagesdir}" cd $topdir +for dist in $dists +do + echo newpkg info for $dist + LANG=C cat "${filesdir}/db/package_names_${dist}.txt" \ + | sort | uniq > "${packagesdir}/package_names_${dist}" + LANG=C cat "${filesdir}/db/source_names_${dist}.txt" \ + | sort | uniq > "${packagesdir}/source_names_${dist}" -./bin/newpkg_info sid + ./bin/newpkg_info ${dist} +done diff --git a/lib/Packages/DoNewPkg.pm b/lib/Packages/DoNewPkg.pm index bde30d7..e5b9e88 100644 --- a/lib/Packages/DoNewPkg.pm +++ b/lib/Packages/DoNewPkg.pm @@ -22,7 +22,7 @@ sub do_newpkg { fatal_error( _g( "suite not valid or not specified" ) ); } if (@{$opts->{suite}} > 1) { - fatal_error( sprintf( _g( "more than one suite specified for show (%s)" ), "@{$opts->{suite}}" ) ); + fatal_error( sprintf( _g( "more than one suite specified for newpkg (%s)" ), "@{$opts->{suite}}" ) ); } my $sort_func = sub { $_[0][0] cmp $_[1][0] }; @@ -36,9 +36,13 @@ sub do_newpkg { $opts->{section}[0] : undef; my @new_pkgs; - #FIXME: move to Packages::DB? - open NEWPKG, '<', "$TOPDIR/files/packages/newpkg_info" - or die "can't read newpkg_info file: $!"; + open NEWPKG, '<', "$TOPDIR/files/packages/newpkg_info_$suite" + or do { + warn "can't read newpkg_info_$suite: $!"; + fatal_error( sprintf( _g("no newpkg information found for suite %s"), + $suite) ); + return; + }; while () { chomp; my @data = split /\s/, $_, 10; -- 2.39.2