From d8b4bc529b8512223dc7ae3c80c5131257658402 Mon Sep 17 00:00:00 2001 From: Pascal Rigaux Date: Thu, 15 May 2008 12:54:33 +0000 Subject: - urpmi.addmedia, urpmi.update: o check downloaded synthesis is not invalid HTML code (#39918) (useful for servers not returning a valid HTTP error) --- urpm/media.pm | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'urpm') diff --git a/urpm/media.pm b/urpm/media.pm index 82338da8..5d788f5a 100644 --- a/urpm/media.pm +++ b/urpm/media.pm @@ -1230,7 +1230,7 @@ sub get_synthesis__remote { my $ok = try__maybe_mirrorlist($urpm, $medium, sub { urpm::download::sync($urpm, $medium, [ _url_with_synthesis($medium) ], quiet => $quiet, callback => $callback) && - file_size(cachedir_with_synthesis($urpm, $medium)) >= 20; + _check_synthesis(cachedir_with_synthesis($urpm, $medium)); }); if (!$ok) { chomp(my $err = $@); @@ -1239,6 +1239,18 @@ sub get_synthesis__remote { $ok; } +sub _check_synthesis { + my ($synthesis_file) = @_; + + file_size($synthesis_file) >= 20 or return; + + # check first 2 lines do not contain typical html code + # this is useful for servers not returning a valid HTTP error (#39918) + open(my $F, '<', $synthesis_file) or return; + my $s = <$F>; $s .= <$F>; + $s !~ /|{cachedir}/partial/" . basename($url); $options->{force} and unlink $f; if (urpm::download::sync($urpm, $medium, [ $url ], - quiet => $options->{quiet}, callback => $options->{callback}) && file_size($f) >= 20) { + quiet => $options->{quiet}, callback => $options->{callback}) && _check_synthesis($f)) { $urpm->{log}(N("found probed synthesis as %s", $url)); 1; } else { -- cgit v1.2.1