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