Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Net-Amazon-S3 CPAN distribution.

Report information
The Basics
Id: 35731
Status: resolved
Priority: 0/
Queue: Net-Amazon-S3

People
Owner: Nobody in particular
Requestors: joey [...] kitenet.net
Cc:
AdminCc:

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



Subject: add_key_filename crashes if the file is empty
add_key_filename dies with "not a readable file with fixed size" if the file is empty. There are, I think, reasonable reasons to want to store empty files in s3. In my case, I just don't want ikiwiki to crash if it happens to have an empty file from a user. And add_key($key, "", ..) works fine, so I currently have a special case in my code that tests if the file is -z and if so, uses add_key rather than add_key_filename..
Subject: PATCH: add_key_filename crashes if the file is empty
On Thu May 08 15:47:38 2008, JOEY wrote: Show quoted text
> add_key_filename dies with "not a readable file with fixed size" if the > file is empty. > > There are, I think, reasonable reasons to want to store empty files in > s3. In my case, I just don't want ikiwiki to crash if it happens to have > an empty file from a user. > > And add_key($key, "", ..) works fine, so I currently have a special case > in my code that tests if the file is -z and if so, uses add_key rather > than add_key_filename..
Attached is a patch for a proper fix
commit b65f4a9b5bba0c8768a9c903b495c61f3b93f947 Author: Bryan Donlan <bdonlan@fushizen.net> Date: Thu Jul 24 21:57:22 2008 -0400 Fix add_key_filename not working when the file is empty diff --git a/lib/Net/Amazon/S3/Bucket.pm b/lib/Net/Amazon/S3/Bucket.pm index fbe79f1..3a07549 100644 --- a/lib/Net/Amazon/S3/Bucket.pm +++ b/lib/Net/Amazon/S3/Bucket.pm @@ -543,7 +543,7 @@ sub _content_sub { my $blksize = $stat->blksize || 4096; croak "$filename not a readable file with fixed size" - unless -r $filename and $remaining; + unless -r $filename and (-f _ || $remaining); my $fh = IO::File->new( $filename, 'r' ) or croak "Could not open $filename: $!"; $fh->binmode; diff --git a/t/01api.t b/t/01api.t index 12742bb..82a1266 100644 --- a/t/01api.t +++ b/t/01api.t @@ -9,7 +9,7 @@ use Test::More; unless ( $ENV{'AMAZON_S3_EXPENSIVE_TESTS'} ) { plan skip_all => 'Testing this module for real costs money.'; } else { - plan tests => 67 * 2 + 4; + plan tests => 71 * 2 + 4; } use_ok('Net::Amazon::S3'); @@ -274,6 +274,19 @@ for my $location ( undef, 'EU' ) { is( $response->{content_length}, 0 ); $bucket_obj->delete_key($keyname); + # how about using add_key_filename? + $keyname .= '4'; + open FILE, ">", "t/empty" or die "Can't open t/empty for write: $!"; + close FILE; + $bucket_obj->add_key_filename($keyname, 't/empty'); + $response = $bucket_obj->get_key($keyname); + is( $response->{value}, '' ); + is( $response->{etag}, 'd41d8cd98f00b204e9800998ecf8427e' ); + is( $response->{content_type}, 'binary/octet-stream' ); + is( $response->{content_length}, 0 ); + $bucket_obj->delete_key($keyname); + unlink 't/empty'; + # fetch contents of the bucket # note prefix, marker, max_keys options can be passed in $response = $bucket_obj->list
Thanks for the bug report and the patch! I've applied it and it will be in the next release of the module. Cheers! Leon