[Bps-public-commit] r11589 - in SVN-PropDB: .

jesse at bestpractical.com jesse at bestpractical.com
Sun Apr 6 07:29:51 EDT 2008


Author: jesse
Date: Sun Apr  6 07:29:46 2008
New Revision: 11589

Modified:
   SVN-PropDB/   (props changed)
   SVN-PropDB/lib/Prophet/Replica.pm

Log:
 r29383 at 68-247-97-201:  jesse | 2008-04-06 01:29:06 -1000
 * Refactor for better sanity


Modified: SVN-PropDB/lib/Prophet/Replica.pm
==============================================================================
--- SVN-PropDB/lib/Prophet/Replica.pm	(original)
+++ SVN-PropDB/lib/Prophet/Replica.pm	Sun Apr  6 07:29:46 2008
@@ -40,8 +40,6 @@
 
 Reblesses this sync source into the right sort of sync source for whatever kind of replica $self->url points to
 
-TODO: currently knows that we only have SVN replicas
-
 
 =cut
 
@@ -463,23 +461,43 @@
     my $path = shift;
 
     my $replica_root = dir( $path, $self->db_uuid );
+    my $cas_dir = dir($replica_root => 'cas');
+    my $record_dir = dir($replica_root => 'records');
     _mkdir($path);
     _mkdir($replica_root);
+    _mkdir( $record_dir);
+    make_tiered_dirs( $cas_dir);
+
+    $self->init_export(root => $replica_root);
+    
+    foreach my $type ( @{ $self->prophet_handle->enumerate_types } ) {
+        $self->export_records(type => $type, root => $replica_root, cas_dir => $cas_dir);
+    }
+
+    $self->export_changesets( root => $replica_root, cas_dir => $cas_dir);
+}
+
+
 
-    open( my $uuidfile, ">", file( $replica_root, 'replica-uuid' ) ) || die $!;
+sub init_export {
+    my $self = shift;
+    my %args = validate(@_, { root => 1});
+
+    open( my $uuidfile, ">", file( $args{'root'}, 'replica-uuid' ) ) || die $!;
     print $uuidfile $self->uuid || die $!;
     close $uuidfile || die $!;
-    open( my $latest, ">", file( $replica_root, 'latest' ) ) || die $!;
+    open( my $latest, ">", file( $args{'root'}, 'latest' ) ) || die $!;
     print $latest $self->most_recent_changeset;
     close $latest || die $!;
+}
 
-    make_tiered_dirs( dir( $replica_root => 'cas' ) );
-    _mkdir( dir( $replica_root => 'records' ) );
-    _mkdir( dir( $replica_root => 'records' => 'some_record_type' ) );
 
-    foreach my $type ( @{ $self->prophet_handle->enumerate_types } ) {
+sub export_records{
+    my $self = shift;
+    my %args = validate(@_, { root => 1, type => 1, cas_dir => 1});
+    my $type = $args{'type'};
 
-        make_tiered_dirs( dir( $replica_root => 'records' => $type ) );
+        make_tiered_dirs( dir( $args{'root'} => 'records' => $type ) );
 
         my $collection = Prophet::Collection->new( handle => $self->prophet_handle, type => $type );
         $collection->matching( sub {1} );
@@ -488,14 +506,14 @@
             my $content = XMLout( $record_as_hash, NoAttr => 1, RootName => 'record' );
             my $fingerprint = sha1_hex($content);
             my $content_filename
-                = file( $replica_root, 'cas', substr( $fingerprint, 0, 1 ), substr( $fingerprint, 1, 1 ),
+                = file( $args{'cas_dir'}, substr( $fingerprint, 0, 1 ), substr( $fingerprint, 1, 1 ),
                 $fingerprint );
             open( my $output, ">", $content_filename ) || die "Could not open $content_filename";
             print $output $content || die $!;
             close $output;
 
             my $idx_filename = file(
-                $replica_root, 'records',$type,
+                $args{'root'}, 'records',$type,
                 substr( $record->uuid, 0, 1 ),
                 substr( $record->uuid, 1, 1 ),
                 $record->uuid
@@ -515,7 +533,12 @@
 
     }
 
-    open( my $cs_file, ">" . file( $replica_root, 'changesets.idx' ) ) || die $!;
+
+sub export_changesets {
+    my $self = shift;
+    my %args = validate(@_,{ root => 1, cas_dir => 1});
+    
+    open( my $cs_file, ">" . file( $args{'root'}, 'changesets.idx' ) ) || die $!;
 
     foreach my $changeset ( @{ $self->fetch_changesets( after => 0 ) } ) {
         my $hash_changeset = $changeset->as_hash;
@@ -525,7 +548,7 @@
         my $content = XMLout( $hash_changeset, NoAttr => 1, RootName => 'changeset' );
         my $fingerprint = sha1_hex($content);
         my $content_filename
-            = file( $replica_root, 'cas', substr( $fingerprint, 0, 1 ), substr( $fingerprint, 1, 1 ), $fingerprint );
+            = file( $args{'cas_dir'}, substr( $fingerprint, 0, 1 ), substr( $fingerprint, 1, 1 ), $fingerprint );
         open( my $output, ">", $content_filename ) || die "Could not open $content_filename";
         print $output $content || die $!;
         close $output;
@@ -557,7 +580,7 @@
 
 }
 
-    sub make_tiered_dirs {
+sub make_tiered_dirs {
         my $base = shift;
         _mkdir(dir($base));
     for my $a (0..9, 'a'..'f') {



More information about the Bps-public-commit mailing list