[Bps-public-commit] Prophet - A disconnected, replicated p2p database branch, master, updated. 686ad629ee9b7d747d50e5231d16a00021d2b475

jesse jesse at bestpractical.com
Sat Jan 31 00:18:57 EST 2009


The branch, master has been updated
       via  686ad629ee9b7d747d50e5231d16a00021d2b475 (commit)
       via  f7d5c6f519837c76c8ddfffbee20ec6eb2f8ecfd (commit)
      from  effe27cf708f7c9cf1aeb843d14acc04f76bb1cf (commit)

Summary of changes:
 lib/Prophet/Replica/prophet.pm |   15 +++------------
 lib/Prophet/Util.pm            |   20 ++++++++++++++++++++
 2 files changed, 23 insertions(+), 12 deletions(-)

- Log -----------------------------------------------------------------
commit f7d5c6f519837c76c8ddfffbee20ec6eb2f8ecfd
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sat Jan 31 00:17:21 2009 -0500

    Extracted file writing from prophet replica to lib/Prophet/Util.pm

diff --git a/lib/Prophet/Util.pm b/lib/Prophet/Util.pm
index 9cd1477..272fcdb 100644
--- a/lib/Prophet/Util.pm
+++ b/lib/Prophet/Util.pm
@@ -1,6 +1,8 @@
 package Prophet::Util;
 use strict;
 use File::Basename;
+use File::Spec;
+use File::Path;
 use Params::Validate;
 
 =head2 updir PATH
@@ -78,4 +80,22 @@ sub escape_utf8 {
     $$ref =~ s/'/'/g;
 }
 
+
+sub write_file {
+    my $self = shift;
+    my %args = validate( @_, { file => 1, content => 1 } );
+
+    my ( undef, $parent, $filename ) = File::Spec->splitpath($args{file});
+    unless ( -d $parent ) {
+        eval { mkpath( [$parent] ) };
+        if ( my $msg = $@ ) {
+            die "Failed to create directory " . $parent . " - $msg";
+        }
+    }
+
+    open( my $fh, ">", $args{file} ) || die $!;
+    print $fh scalar( $args{'content'} )
+        ; # can't do "||" as we die if we print 0" || die "Could not write to " . $args{'path'} . " " . $!;
+    close $fh || die $!;
+}
 1;

commit 686ad629ee9b7d747d50e5231d16a00021d2b475
Author: Jesse Vincent <jesse at bestpractical.com>
Date:   Sat Jan 31 00:18:08 2009 -0500

    Using new file writing methods from Prophet::Util

diff --git a/lib/Prophet/Replica/prophet.pm b/lib/Prophet/Replica/prophet.pm
index 1d36431..9bc27fa 100644
--- a/lib/Prophet/Replica/prophet.pm
+++ b/lib/Prophet/Replica/prophet.pm
@@ -770,20 +770,11 @@ sub _write_file {
     my %args = validate( @_, { path => 1, content => 1 } );
 
     my $file = File::Spec->catfile( $self->fs_root => $args{'path'} );
-    my ( undef, $parent, $filename ) = File::Spec->splitpath($file);
-    unless ( -d $parent ) {
-        eval { mkpath( [$parent] ) };
-        if ( my $msg = $@ ) {
-            die "Failed to create directory " . $parent . " - $msg";
-        }
-    }
-
-    open( my $fh, ">$file" ) || die $!;
-    print $fh scalar( $args{'content'} )
-        ; # can't do "||" as we die if we print 0" || die "Could not write to " . $args{'path'} . " " . $!;
-    close $fh || die $!;
+    Prophet::Util->write_file( file => $file, content => $args{content});
 }
 
+
+
 =head2 _file_exists PATH
 
 Returns true if PATH is a file or directory in this replica's directory structure

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list