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