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) --- NEWS | 2 ++ urpm/media.pm | 16 ++++++++++++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/NEWS b/NEWS index bb95dc69..40959cb0 100644 --- a/NEWS +++ b/NEWS @@ -2,6 +2,8 @@ o add missing mark in "Do you want to add media '%s'?" message (from Nikos) - urpmi.addmedia, urpmi.update: o fix checking synthesis MD5SUM + o check downloaded synthesis is not invalid HTML code (#39918) + (useful for servers not returning a valid HTTP error) Version 5.19 - 3 April 2008, by Pascal "Pixel" Rigaux 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