[1/2] Pakfire: abort download if downloaded size is emtpy or zero
Commit Message
In case a download fails for whatever reason, and the downloaded
file size cannot be determined or is zero, Pakfire should abort.
Signed-off-by: Peter Müller <peter.mueller@link38.eu>
---
src/pakfire/lib/functions.pl | 9 ++++++++-
1 file changed, 8 insertions(+), 1 deletion(-)
@@ -180,7 +180,14 @@ sub fetchfile {
my $result = $ua->head($url);
my $remote_headers = $result->headers;
$total_size = $remote_headers->content_length;
- logger("DOWNLOAD INFO: $file has size of $total_size bytes");
+
+ # validate if file download was successful (size <= 0)
+ if ( $total_size eq "0" || not $total_size ) {
+ logger("DOWNLOAD ERROR: download of $file failed with size '$total_size' bytes");
+ return 1;
+ } else {
+ logger("DOWNLOAD INFO: $file has size of $total_size bytes");
+ }
my $response = $ua->get($url, ':content_cb' => \&callback );
message("");