diff options
Diffstat (limited to 'lib/MGA')
-rw-r--r-- | lib/MGA/Advisories.pm | 54 |
1 files changed, 51 insertions, 3 deletions
diff --git a/lib/MGA/Advisories.pm b/lib/MGA/Advisories.pm index dbb7408..3752250 100644 --- a/lib/MGA/Advisories.pm +++ b/lib/MGA/Advisories.pm @@ -5,14 +5,18 @@ use strict; use YAML qw(LoadFile DumpFile Load); use Template; use DateTime; +use DateTime::Format::ISO8601; use Email::Sender::Simple qw(try_to_sendmail); use Email::Simple; use Email::Simple::Creator; +use Fcntl qw(SEEK_END); use HTTP::Request; use LWP::UserAgent; use Parallel::ForkManager; use File::Basename; use XMLRPC::Lite; +use XML::XPath; +use XML::XPath::XMLParser; use Term::ReadKey; #use Data::Dump qw(dd); @@ -169,6 +173,9 @@ sub login_bz { sub get_advisories_from_dir { + # Retrieve last modified dates from SVN + my $modified = get_modified(); + my %advisories; foreach my $advfile (glob "$config->{advisories_dir}/*.adv") { my $adv; @@ -180,9 +187,9 @@ sub get_advisories_from_dir { print $@; next; } + $adv->{ref} = basename($advfile, ".adv"); if (!$adv->{ID}) { next unless $config->{mode} eq 'qa'; - $adv->{ref} = basename($advfile, ".adv"); $adv->{ID} = next_id('TODO', keys %advisories); $adv->{no_save_status} = 1; } @@ -192,6 +199,11 @@ sub get_advisories_from_dir { $advisories{$adv->{ID}} = $adv; my $statusfile = status_file($adv->{ID}); $adv->{status} = -f $statusfile ? LoadFile($statusfile) : {}; + my $fn = $adv->{ref} = basename($advfile); + if (exists $modified->{$fn}) { + # Pull the modified date into the advisory + $adv->{status}{modified} = $modified->{$fn}; + } } return \%advisories; } @@ -221,6 +233,16 @@ sub assign_id { return; } + # Appending the ID later assumes that the file ends in a newline + open(my $fha, "<", $advfile); + seek($fha, -1, SEEK_END); + my $c = <$fha>; + close($fha); + if ($c ne "\n") { + print STDERR "$advname missing newline at end of file\n"; + return; + } + my $adv = LoadFile($advfile); if ($adv->{ID}) { print STDERR "$advname already has an ID assigned: $adv->{ID}\n"; @@ -446,7 +468,7 @@ sub assign_ids { my %advdb; $advdb{advisories} = get_advisories_from_dir(); sort_advisories(\%advdb); - output_pages(); + output_pages(\%advdb); # We will have exited by now in the event of e.g. a Yaml or processing error @@ -619,8 +641,33 @@ sub process_template { } } +# Get the last modified date for each advisory file from SVN +sub get_modified { + my $xml = `svn status -v --xml`; + my $xp = XML::XPath->new(xml => $xml); + my $nodeset = $xp->find('/status/target/entry'); + my %modified; + foreach my $node ($nodeset->get_nodelist) { + my $path = $node->findvalue('@path')->value(); + my $datez = $node->findvalue('wc-status/commit/date')->value(); + if ($path and $datez) { + my $timestamp = DateTime::Format::ISO8601->parse_datetime($datez); + $modified{$path} = $timestamp->epoch; + } + } + return \%modified; +} + # Max 10 processes for processing templates my $pm = Parallel::ForkManager->new(10); +$pm->run_on_finish(\¶llel_finish); +my $parallelerror = 0; + +# Store error flag from forked process +sub parallel_finish { + my ($pid, $exit_code, $ident) = @_; + $parallelerror |= $exit_code; +} # Run process_template in its own process. The process creation overhead is # high, so this only makes sense for templates that interate over all or most @@ -633,9 +680,10 @@ sub parallel_process_template { } } -# Wait for all processes to finish +# Wait for all processes to finish & die if any returned an error sub parallel_complete { $pm->wait_all_children; + die "Error writing output" if $parallelerror; } sub output_pages { |