[Rt-commit] r6173 - in Mnemonic: . lib lib/Mnemonic lib/Mnemonic/Backend

jesse at bestpractical.com jesse at bestpractical.com
Sat Oct 7 03:01:39 EDT 2006


Author: jesse
Date: Sat Oct  7 03:01:39 2006
New Revision: 6173

Added:
   Mnemonic/lib/Mnemonic/Stash.pm
Modified:
   Mnemonic/   (props changed)
   Mnemonic/bin/mnemonic
   Mnemonic/lib/Mnemonic.pm
   Mnemonic/lib/Mnemonic/Backend/Tmp.pm
   Mnemonic/lib/Mnemonic/FileSet.pm

Log:
 r28072 at pinglin:  jesse | 2006-10-06 22:13:02 -0400
 *checkpoint


Modified: Mnemonic/bin/mnemonic
==============================================================================
--- Mnemonic/bin/mnemonic	(original)
+++ Mnemonic/bin/mnemonic	Sat Oct  7 03:01:39 2006
@@ -15,6 +15,7 @@
             'index',
             'path=s@',
             'skip=s@',
+            'target=s',
             'delete_key|delete-key=s',
             'dry_run|dry-run'
         );
@@ -44,5 +45,5 @@
         $b->list_backup_files( manifest_id => $argv{'list'} );
     }
     if ($argv{'restore'}) {
-        $b->restore( manifest_id => $argv{'restore'} );
+        $b->restore( manifest_id => $argv{'restore'}, restore_root => $argv{'target'} );
     }

Modified: Mnemonic/lib/Mnemonic.pm
==============================================================================
--- Mnemonic/lib/Mnemonic.pm	(original)
+++ Mnemonic/lib/Mnemonic.pm	Sat Oct  7 03:01:39 2006
@@ -24,17 +24,13 @@
     my $self = shift;
     $self->load_config();
 
-    $self->pgp(
-        Mnemonic::Crypto::OpenPGP->new( { config => $self->config } ) );
+    $self->pgp( Mnemonic::Crypto::OpenPGP->new( { config => $self->config } ) );
     my $backend = $self->config->{'backend'} || "Mnemonic::Backend::Tmp";
     $backend->require() || die $@;
     $self->backend( $backend->new( { config => $self->config() } ) );
     $self->backend->init();
-    warn "newing stash";
     $self->stash( Mnemonic::Stash->new( { config => $self->config } ) );
-    warn "intting";
     $self->stash->init();
-    warn "STash initted";
 }
 
 sub load_config {
@@ -197,9 +193,10 @@
                         } else {
                             $self->encrypt_and_store(
                                 $checksum => $chunk_ref );
-                            warn "\t+ $filename (from "
-                                . $start_at
-                                . ") stored\n";
+                            warn "\t+ $filename ";
+                            
+                           warn "(from " . $start_at . ") " if ($start_ad > 0);
+                           warn "stored\n";
                         }
                         push @subkeys, $checksum;
                         $start_at += $CHUNKSIZE;

Modified: Mnemonic/lib/Mnemonic/Backend/Tmp.pm
==============================================================================
--- Mnemonic/lib/Mnemonic/Backend/Tmp.pm	(original)
+++ Mnemonic/lib/Mnemonic/Backend/Tmp.pm	Sat Oct  7 03:01:39 2006
@@ -17,9 +17,9 @@
     my $self = shift;
     my $host =`hostname`;
     chomp $host;
+    my $path = $self->config->{'filesys'}{'store'} || File::Spec->catpath('tmp','mnemonic');
 
-
-    $self->path('/tmp/mnemonic');
+    $self->path($path);
     mkdir ($self->path);
     $self->id($host.":" . $self->path);
 

Modified: Mnemonic/lib/Mnemonic/FileSet.pm
==============================================================================
--- Mnemonic/lib/Mnemonic/FileSet.pm	(original)
+++ Mnemonic/lib/Mnemonic/FileSet.pm	Sat Oct  7 03:01:39 2006
@@ -30,20 +30,19 @@
     my $self = shift;
     $self->init();
     my @files;
-    my @regexen = @{$self->skip_regexes}; 
-    $|++; # turn off buffering
-    my $count = 0;
+    my @regexen = @{ $self->skip_regexes };
+    $|++;    # turn off buffering
+    my $count   = 0;
     my $skipped = 0;
-    my $last = 0;
-    print "Looking:\n\n";
-    File::Find::finddepth( sub { 
-    return if (map { $File::Find::name =~ $_ } @regexen);
-    &{$self->on_match()};
+    my $last    = 0;
+    print "Looking in: " . join(', ', @{$self->search_paths||[]});
+    File::Find::finddepth(
+        sub {
+            return if ( map { $File::Find::name =~ $_ } @regexen );
+            &{ $self->on_match() };
 
-}
-
-    
-    , @{$self->search_paths});
+            } , @{ $self->search_paths||[] }
+    );
     return @files;
 }
 

Added: Mnemonic/lib/Mnemonic/Stash.pm
==============================================================================
--- (empty file)
+++ Mnemonic/lib/Mnemonic/Stash.pm	Sat Oct  7 03:01:39 2006
@@ -0,0 +1,108 @@
+package Mnemonic::Stash;
+use warnings;
+use strict;
+
+use base qw/Class::Accessor/;
+
+__PACKAGE__->mk_accessors(qw/handle/);
+
+use Jifty::DBI::Handle;
+use Jifty::DBI::SchemaGenerator;
+use Mnemonic::Stash::Checksum;
+my $FILE=       $ENV{'HOME'}.  '/.mnemonic_checksums';
+
+my $item = __PACKAGE__->new();
+$item->init();
+sub init {
+    my $self   = shift;
+    if (-f $FILE) {
+    $self->_connect();
+    } else {
+    $self->_connect();
+    $self->_generate_db();
+}
+}
+
+sub _generate_db {
+    my $self = shift;
+    my $gen = Jifty::DBI::SchemaGenerator->new( $self->handle );
+    $gen->add_model( Mnemonic::Stash::Checksum->new( handle => $self->handle ) );
+    my @statements = $gen->create_table_sql_statements;
+    $self->handle->begin_transaction;
+    for my $statement (@statements) {
+        my $ret = $self->handle->simple_query($statement);
+    }
+    $self->handle->commit;
+
+}
+
+
+sub _connect {
+    my $self = shift;
+
+
+    my $handle = Jifty::DBI::Handle->new();
+    $handle->connect(
+        driver   => "SQLite",
+        database => $FILE
+    );
+    $self->handle($handle);
+}
+
+
+sub store_file_info {
+    my $self = shift;
+    my %args = (
+        filename => undef,
+        subkeys     => undef,
+        statinfo => undef,
+        sha256   => undef,
+        object_type     => undef,
+        backend => undef,
+        @_
+    );
+
+    my $item = Mnemonic::Stash::Checksum->new( handle => $self->handle );
+    return $item->create(
+        path     => $args{filename},
+        sha256   => $args{sha256},
+        object_type     => $args{type},
+        statinfo =>$args{'statinfo'} ,
+        filesize => $args{'statinfo'}->[7],
+        mtime => $args{'statinfo'}->[9],
+        ctime => $args{'statinfo'}->[10],
+        stored_to => $args{'backend'}->id,
+        subkeys     =>$args{'subkeys'} 
+    );
+}
+
+sub already_stored {
+    my $self = shift;
+    my $backend = shift;
+    my $filename = shift;
+    my $statinfo = shift;
+
+    my $item = Mnemonic::Stash::Checksum->new(handle => $self->handle);
+    $item->load_by_cols( stored_to => $backend->id, path => $filename, ctime=> $statinfo->[10], mtime => $statinfo->[9], filesize => $statinfo->[7]);
+    if($item->id) {
+        return $item;
+    } else {
+        return undef;
+    }
+}
+
+sub has_hash_of_file_content {
+    my $self = shift;
+    my $backend = shift;
+    my $sha256 =shift;
+    my $item = Mnemonic::Stash::Checksum->new(handle => $self->handle);
+    $item->load_by_cols( stored_to => $backend->id, sha256 => $sha256);
+    if($item->id) {
+        return $item;
+    } else {
+        return undef;
+    }
+
+}
+
+1;


More information about the Rt-commit mailing list