[Bps-public-commit] r12446 - in Prophet/trunk: .

jesse at bestpractical.com jesse at bestpractical.com
Sat May 17 05:32:15 EDT 2008


Author: jesse
Date: Sat May 17 05:32:14 2008
New Revision: 12446

Modified:
   Prophet/trunk/   (props changed)
   Prophet/trunk/lib/Prophet/Replica.pm

Log:
 r31111 at dhcp113 (orig r12380):  sartak | 2008-05-16 20:32:37 +0900
  r55975 at onn:  sartak | 2008-05-16 07:32:09 -0400
  Add external metadata read/write methods
 


Modified: Prophet/trunk/lib/Prophet/Replica.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/Replica.pm	(original)
+++ Prophet/trunk/lib/Prophet/Replica.pm	Sat May 17 05:32:14 2008
@@ -7,6 +7,7 @@
 use Params::Validate qw(:all);
 use UNIVERSAL::require;
 use Data::UUID;
+use Path::Class;
 
 
 __PACKAGE__->mk_accessors(qw(state_handle resolution_db_handle is_resdb is_state_handle db_uuid url));
@@ -464,6 +465,52 @@
     $exporter->export();
 }
 
+=head2 metadata_directory
+
+=cut
+
+sub metadata_directory {
+    my $self = shift;
+    return $ENV{PROPHET_METADATA_DIRECTORY} if $ENV{PROPHET_METADATA_DIRECTORY};
+    return dir($ENV{HOME}, '.prophet-meta', $self->uuid);
+}
+
+=head2 read_metadata_file
+
+Returns the contents of the given file in this replica's metadata directory.
+Returns C<undef> if the file does not exist.
+
+=cut
+
+sub read_metadata_file {
+    my $self = shift;
+    my %args = validate( @_, { path => 1 } );
+    my $file = file($self->metadata_directory, $args{path});
+
+    return undef if !-f $file;
+    return scalar $file->slurp;
+}
+
+=head2 write_metadata_file
+
+Writes the given string to the given file in this replica's metadata directory.
+
+=cut
+
+sub write_metadata_file {
+    my $self = shift;
+    my %args = validate( @_, { path => 1, content => 1 } );
+    my $file = file($self->metadata_directory, $args{path});
+
+    my $parent = $file->parent;
+    if (!-d $parent) {
+        $parent->mkpath || die "Failed to create directory " . $file->parent;
+    }
+
+    my $fh = $file->openw;
+    print $fh $args{content};
+    close $fh || die $!;
+}
 
 =head1 methods to be implemented by a replica backend
 



More information about the Bps-public-commit mailing list