[libcatmandu-perl] 21/30: Upload should return number of bytes as documented

Jonas Smedegaard dr at jones.dk
Tue Dec 19 11:10:14 UTC 2017


This is an automated email from the git hooks/post-receive script.

js pushed a commit to annotated tag debian/1.0700-1
in repository libcatmandu-perl.

commit 437839ce9746c292dd7eed1673bd601ab6dcb162
Author: Patrick Hochstenbach <patrick.hochstenbach at ugent.be>
Date:   Tue Oct 31 15:25:12 2017 +0100

    Upload should return number of bytes as documented
---
 lib/Catmandu/FileBag.pm               | 17 +++++++++++++++--
 lib/Catmandu/Store/File/Multi/Bag.pm  | 18 ++++++++++++++++--
 lib/Catmandu/Store/File/Simple/Bag.pm |  6 +++---
 3 files changed, 34 insertions(+), 7 deletions(-)

diff --git a/lib/Catmandu/FileBag.pm b/lib/Catmandu/FileBag.pm
index fab1a7b..e32857e 100644
--- a/lib/Catmandu/FileBag.pm
+++ b/lib/Catmandu/FileBag.pm
@@ -39,7 +39,20 @@ sub upload {
     check_string($id);
     check_invocant($io);
 
-    is_hash_ref $self->add({_id => $id, _stream => $io});
+    $self->add({_id => $id, _stream => $io});
+
+    my $file = $self->get($id);
+
+    if (!defined($file)) {
+        return 0;
+    }
+    elsif (is_hash_ref($file)) {
+        return $file->{size};
+    }
+    else {
+        $self->log->error("expecting a HASH but got `$file'");
+        return 0;
+    }
 }
 
 1;
@@ -99,7 +112,7 @@ the number of bytes written.
 =head2 stream($io, $file)
 
 A helper application to stream the contents of a L<Catmandu::FileBag> item
-to an IO::Handle. Returns the nuber of bytes written.
+to an IO::Handle. Returns the number of bytes written.
 
 =head2 as_string($file)
 
diff --git a/lib/Catmandu/Store/File/Multi/Bag.pm b/lib/Catmandu/Store/File/Multi/Bag.pm
index 6c883df..f71dcba 100644
--- a/lib/Catmandu/Store/File/Multi/Bag.pm
+++ b/lib/Catmandu/Store/File/Multi/Bag.pm
@@ -5,6 +5,8 @@ use Catmandu::Sane;
 our $VERSION = '1.0606';
 
 use Moo;
+use Catmandu::Util qw(:is);
+use Catmandu::Logger;
 use namespace::clean;
 
 extends 'Catmandu::Store::Multi::Bag';
@@ -29,7 +31,8 @@ sub upload {
                     unless $io->isa('IO::Seekable');
                 $io->seek(0, 0);
             }
-            $store->bag($self->name)->upload($io, $id) || return undef;
+            $store->bag($self->name)->upload($io, $id) ||
+                $self->log->error("failed to upload $id to " . $self->name);
             $rewind = 1;
         }
         else {
@@ -39,7 +42,18 @@ sub upload {
         }
     }
 
-    1;
+    my $file = $self->get($id);
+
+    if (!defined($file)) {
+        return 0;
+    }
+    elsif (is_hash_ref($file)) {
+        return $file->{size};
+    }
+    else {
+        $self->log->error("expecting a HASH but got `$file'");
+        return 0;
+    }
 }
 
 1;
diff --git a/lib/Catmandu/Store/File/Simple/Bag.pm b/lib/Catmandu/Store/File/Simple/Bag.pm
index a2f5ca0..d04151a 100644
--- a/lib/Catmandu/Store/File/Simple/Bag.pm
+++ b/lib/Catmandu/Store/File/Simple/Bag.pm
@@ -119,13 +119,13 @@ sub add {
     my $file = File::Spec->catfile($path, $packed_key);
 
     if (Catmandu::Util::is_invocant($io)) {
-        return copy($io, $file);
+        copy($io, $file) || Catmandu::Error->throw("failed to write file : $!");
     }
     else {
-        return Catmandu::Util::write_file($file, $io);
+        Catmandu::Util::write_file($file, $io) || Catmandu::Error->throw("failed to write file : $!");
     }
 
-    return $self->get($id);
+    1;
 }
 
 sub delete {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-perl/packages/libcatmandu-perl.git



More information about the Pkg-perl-cvs-commits mailing list