From 6103e15ffa844e64ff95b2bfe78c83dd910fbe0e Mon Sep 17 00:00:00 2001 From: Frédéric Buclin Date: Mon, 28 Nov 2011 17:08:10 +0100 Subject: Bug 705393: Improve the error message thrown by Update.pm when updates.bugzilla.org is unavailable r=glob a=LpSolit --- Bugzilla/Update.pm | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) (limited to 'Bugzilla/Update.pm') diff --git a/Bugzilla/Update.pm b/Bugzilla/Update.pm index a94fd167d..c9942a4f0 100644 --- a/Bugzilla/Update.pm +++ b/Bugzilla/Update.pm @@ -20,8 +20,6 @@ use strict; use Bugzilla::Constants; -use constant REMOTE_FILE => 'http://updates.bugzilla.org/bugzilla-update.xml'; -use constant LOCAL_FILE => "/bugzilla-update.xml"; # Relative to datadir. use constant TIME_INTERVAL => 86400; # Default is one day, in seconds. use constant TIMEOUT => 5; # Number of seconds before timeout. @@ -30,26 +28,25 @@ sub get_notifications { return if !Bugzilla->feature('updates'); return if (Bugzilla->params->{'upgrade_notification'} eq 'disabled'); - my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; + my $local_file = bz_locations()->{'datadir'} . '/' . LOCAL_FILE; # Update the local XML file if this one doesn't exist or if # the last modification time (stat[9]) is older than TIME_INTERVAL. if (!-e $local_file || (time() - (stat($local_file))[9] > TIME_INTERVAL)) { unlink $local_file; # Make sure the old copy is away. - if (-e $local_file) { - return { 'error' => 'no_update', xml_file => $local_file }; - } + return { 'error' => 'no_update' } if (-e $local_file); + my $error = _synchronize_data(); # If an error is returned, leave now. return $error if $error; } # If we cannot access the local XML file, ignore it. - return {'error' => 'no_access', 'xml_file' => $local_file} unless (-r $local_file); + return { 'error' => 'no_access' } unless (-r $local_file); my $twig = XML::Twig->new(); $twig->safe_parsefile($local_file); # If the XML file is invalid, return. - return {'error' => 'corrupted', 'xml_file' => $local_file} if $@; + return { 'error' => 'corrupted' } if $@; my $root = $twig->root; my @releases; @@ -119,7 +116,7 @@ sub get_notifications { } sub _synchronize_data { - my $local_file = bz_locations()->{'datadir'} . LOCAL_FILE; + my $local_file = bz_locations()->{'datadir'} . '/' . LOCAL_FILE; my $ua = LWP::UserAgent->new(); $ua->timeout(TIMEOUT); @@ -133,7 +130,7 @@ sub _synchronize_data { else { $ua->env_proxy; } - $ua->mirror(REMOTE_FILE, $local_file); + my $response = eval { $ua->mirror(REMOTE_FILE, $local_file) }; # $ua->mirror() forces the modification time of the local XML file # to match the modification time of the remote one. @@ -144,11 +141,14 @@ sub _synchronize_data { # Try to alter its last modification time. my $can_alter = utime(undef, undef, $local_file); # This error should never happen. - $can_alter || return {'error' => 'no_update', 'xml_file' => $local_file}; + $can_alter || return { 'error' => 'no_update' }; } - else { + elsif ($response && $response->is_error) { # We have been unable to download the file. - return {'error' => 'cannot_download', 'xml_file' => $local_file}; + return { 'error' => 'cannot_download', 'reason' => $response->status_line }; + } + else { + return { 'error' => 'no_write', 'reason' => $@ }; } # Everything went well. -- cgit v1.2.3-24-g4f1b