Skip to content

Instantly share code, notes, and snippets.

@dblackdblack
Created July 16, 2013 19:04
Show Gist options
  • Save dblackdblack/6011605 to your computer and use it in GitHub Desktop.
Save dblackdblack/6011605 to your computer and use it in GitHub Desktop.
===================================================================
--- perllib/bepress/ArticleStorage.pm (revision 38147)
+++ perllib/bepress/ArticleStorage.pm (working copy)
@@ -1164,15 +1164,21 @@
# within it. $to won't have a representation in the ArticleStorage layer.
#
# $to_path is not constrained to be under fsroot, or even expected to be under there.
+# $to_path might also be a filehandle to be written to, rather than a path.
#
##########################################
sub copy_to_local {
my ($self, $from_path, $to_path, $site_key) = @_;
if (my $file_obj = $self->load_from_db($from_path, $site_key)){
+
+ my $outfh;
+ if( Scalar::Util::openhandle($to_path) ) { # the dest path is actually a filehandle, not a path
+ $outfh = $to_path;
+ } else {
+ open ($outfh, ">:raw", $to_path) || be::Ex->throw("can't write to $to_path $!");
+ }
- open (my $outfh, ">:raw", $to_path) || bp::Ex->throw("can't write to $to_path $!");
-
# empty files aren't in mogilefs (though they are in the database), so we
# can't call get_authoritative_handle(), so we need to stop here
if ($file_obj->is_empty_file){
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment