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