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