IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 17610


Ignore:
Timestamp:
May 9, 2008, 11:15:07 AM (18 years ago)
Author:
jhoblitt
Message:

change Nebulous::Client->replicate() to check the md5sum of the replicated file and to not leave empty instances laying around if there is a failure

Location:
trunk/Nebulous
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/Nebulous/Build.PL

    r17079 r17610  
    8080    create_makefile_pl  => 'passthrough',
    8181    requires            => {
     82        'Digest::MD5'           => 0,
    8283        'File::Copy'            => 0,
    8384        'Time::HiRes'           => 0,
  • trunk/Nebulous/Changes

    r17547 r17610  
    22
    330.09
     4    - change Nebulous::Client->replicate() to check the md5sum of the
     5      replicated file and to not leave empty instances laying around if there
     6      is a failure
    47    - add a virtual "summary" volume to neb-df
    58    - fix neb-df coding issues
  • trunk/Nebulous/lib/Nebulous/Client.pm

    r17538 r17610  
    11# Copyright (c) 2004-2008  Joshua Hoblitt
    22#
    3 # $Id: Client.pm,v 1.45 2008-05-06 03:03:50 jhoblitt Exp $
     3# $Id: Client.pm,v 1.46 2008-05-09 21:15:07 jhoblitt Exp $
    44
    55package Nebulous::Client;
     
    1111our $VERSION = '0.08';
    1212
     13use Digest::MD5;
    1314use File::Copy qw();
    1415use Log::Log4perl qw(get_logger :levels);
     
    217218    my $new_fh;
    218219    eval {
    219         $new_fh = _open_uri( $uri, '>' );
     220        # must open read/write so we can check the md5sum
     221        $new_fh = _open_uri( $uri, '+>' );
    220222    };
    221223    $log->logdie( $@ ) if $@;
    222224
    223     File::Copy::copy( $fh, $new_fh ) or $log->logdie( "can not copy instance $uri" );
     225    my $success = File::Copy::copy( $fh, $new_fh );
     226    unless ($success) {
     227        $self->delete_instance("$uri");
     228        $log->logdie( "can not copy instance $uri" );
     229    }
     230
     231    # check md5sum
     232    my $src_md5 = Digest::MD5->new->addfile($fh)->hexdigest;
     233    $log->debug( "md5sum src instance: $src_md5" );
     234    my $dst_md5 = Digest::MD5->new->addfile($new_fh)->hexdigest;
     235    $log->debug( "md5sum dst instance: $dst_md5" );
     236
     237    unless ($src_md5 eq $dst_md5) {
     238        $self->delete_instance("$uri");
     239        $log->logdie( "md5sum mismatch" );
     240    }
    224241
    225242    $log->debug( "copied instance" );
     
    232249    return $uri;
    233250}
     251
    234252
    235253sub cull {
Note: See TracChangeset for help on using the changeset viewer.