Skip Menu |

This queue is for tickets about the libwww-perl CPAN distribution.

Report information
The Basics
Id: 48236
Status: resolved
Priority: 0/
Queue: libwww-perl

Owner: Nobody in particular
Requestors: SREZIC [...]

Bug Information
Severity: (no value)
Broken in: 5.830
Fixed in: (no value)

Download (untitled) / with headers
text/plain 919b
In some situations LWP::UserAgent::mirror gives a bad error message in the form "Transfer truncated: only out of ... bytes received". This seems to happen if something calls die() while in the request callback. This only sets X-Died, but nothing checks for this value. My attached patch changes this to check X-Died, and if it is set, to die with that value, which gives better error messages. The second attached file is a test script which should work under Unix systems (probably does not work under Windows) and shows the behavior with and without the patch. (The test script also reveals the problem that mirror() expects that the directory containing the output file is writable. Maybe a workaround could be to write to a temporary file under /tmp (or whatever File::Temp uses), but unfortunately a rename() would not be anymore atomic if /tmp is on another partition then the output file) Regards, Slaven
#!/usr/bin/perl # use strict; use warnings; use Test::More tests => 3; use File::Temp qw(tempdir); use LWP::UserAgent; my $srcdir = tempdir(CLEANUP => 1); my $destdir = tempdir(CLEANUP => 1); open my $ofh, ">", "$srcdir/test" or die $!; print $ofh "Test\n"; close $ofh; utime 0, 0, "$srcdir/test"; my $ua = LWP::UserAgent->new; { my $resp = $ua->mirror("file://$srcdir", "$destdir/test"); ok($resp->is_success); } utime 0, 0, "$destdir/test"; utime time, time, "$srcdir/test"; chmod 0500, $destdir; { my $resp = eval { $ua->mirror("file://$srcdir", "$destdir/test") }; my $err = $@; ok(!$resp); like($err, qr{Can't write to}); } __END__
Subject: LWP-mirror-permissions.patch
From 5b220a82fb48a41d6c3dc327f7f8ce54600aceb4 Mon Sep 17 00:00:00 2001 From: Slaven Rezic <> Date: Mon, 27 Jul 2009 15:09:05 +0200 Subject: [PATCH] mirror should die in case X-Died is set --- lib/LWP/ | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/lib/LWP/ b/lib/LWP/ index d932085..3d1aecf 100644 --- a/lib/LWP/ +++ b/lib/LWP/ @@ -834,6 +834,9 @@ sub mirror my $tmpfile = "$file-$$"; my $response = $self->request($request, $tmpfile); + if ( $response->header('X-Died') ) { + die $response->header('X-Died'); + } # Only fetching a fresh copy of the would be considered success. # If the file was not modified, "304" would returned, which --
Download (untitled) / with headers
text/plain 106b
Thanks. Applied as < perl/commit/b90df0a3fccc3faf4b71c7869f0af5d28d9acd6a>

This service is sponsored and maintained by Best Practical Solutions and runs on infrastructure.

Please report any issues with to