[1/2] Pakfire: abort download if downloaded size is emtpy or zero

Message ID 20181022175813.3938-1-peter.mueller@link38.eu
State Dropped
Headers
Series [1/2] Pakfire: abort download if downloaded size is emtpy or zero |

Commit Message

Peter Müller Oct. 23, 2018, 4:58 a.m. UTC
  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(-)
  

Patch

diff --git a/src/pakfire/lib/functions.pl b/src/pakfire/lib/functions.pl
index 12a405bd7..bbc580ad2 100644
--- a/src/pakfire/lib/functions.pl
+++ b/src/pakfire/lib/functions.pl
@@ -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("");