fa408f
From ddda87fb08ca523115be1ffd6dec8442e47bc20b Mon Sep 17 00:00:00 2001
fa408f
From: =?UTF-8?q?Petr=20P=C3=ADsa=C5=99?= <ppisar@redhat.com>
fa408f
Date: Wed, 27 Nov 2013 10:45:39 +0100
fa408f
Subject: [PATCH] Croak on failed write into a file
fa408f
MIME-Version: 1.0
fa408f
Content-Type: text/plain; charset=UTF-8
fa408f
Content-Transfer-Encoding: 8bit
fa408f
fa408f
The mirror() method saves a document into a file. Any error while
fa408f
writing to the file, e.g. no disk space, was ignored. This patch fixes
fa408f
it by croaking on such I/O error.
fa408f
fa408f
Signed-off-by: Petr Písař <ppisar@redhat.com>
fa408f
---
fa408f
 lib/HTTP/Tiny.pm | 5 ++++-
fa408f
 1 file changed, 4 insertions(+), 1 deletion(-)
fa408f
fa408f
diff --git a/lib/HTTP/Tiny.pm b/lib/HTTP/Tiny.pm
fa408f
index 541befe..b3fffd0 100644
fa408f
--- a/lib/HTTP/Tiny.pm
fa408f
+++ b/lib/HTTP/Tiny.pm
fa408f
@@ -300,7 +300,10 @@ sub mirror {
fa408f
     sysopen my $fh, $tempfile, Fcntl::O_CREAT()|Fcntl::O_EXCL()|Fcntl::O_WRONLY()
fa408f
        or _croak(qq/Error: Could not create temporary file $tempfile for downloading: $!\n/);
fa408f
     binmode $fh;
fa408f
-    $args->{data_callback} = sub { print {$fh} $_[0] };
fa408f
+    $args->{data_callback} = sub {
fa408f
+        print {$fh} $_[0]
fa408f
+        or _croak(qq/Error: Could not write into temporary file $tempfile: $!\n/);
fa408f
+    };
fa408f
     my $response = $self->request('GET', $url, $args);
fa408f
     close $fh
fa408f
         or _croak(qq/Error: Caught error closing temporary file $tempfile: $!\n/);
fa408f
-- 
fa408f
2.7.4
fa408f