Index: trunk/Nebulous/lib/Nebulous/Client.pm
===================================================================
--- trunk/Nebulous/lib/Nebulous/Client.pm	(revision 17542)
+++ trunk/Nebulous/lib/Nebulous/Client.pm	(revision 17610)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004-2008  Joshua Hoblitt
 #
-# $Id: Client.pm,v 1.45 2008-05-06 03:03:50 jhoblitt Exp $
+# $Id: Client.pm,v 1.46 2008-05-09 21:15:07 jhoblitt Exp $
 
 package Nebulous::Client;
@@ -11,4 +11,5 @@
 our $VERSION = '0.08';
 
+use Digest::MD5;
 use File::Copy qw();
 use Log::Log4perl qw(get_logger :levels);
@@ -217,9 +218,25 @@
     my $new_fh;
     eval {
-        $new_fh = _open_uri( $uri, '>' );
+        # must open read/write so we can check the md5sum
+        $new_fh = _open_uri( $uri, '+>' );
     };
     $log->logdie( $@ ) if $@;
 
-    File::Copy::copy( $fh, $new_fh ) or $log->logdie( "can not copy instance $uri" );
+    my $success = File::Copy::copy( $fh, $new_fh );
+    unless ($success) {
+        $self->delete_instance("$uri");
+        $log->logdie( "can not copy instance $uri" );
+    } 
+
+    # check md5sum
+    my $src_md5 = Digest::MD5->new->addfile($fh)->hexdigest;
+    $log->debug( "md5sum src instance: $src_md5" );
+    my $dst_md5 = Digest::MD5->new->addfile($new_fh)->hexdigest;
+    $log->debug( "md5sum dst instance: $dst_md5" );
+
+    unless ($src_md5 eq $dst_md5) {
+        $self->delete_instance("$uri");
+        $log->logdie( "md5sum mismatch" );
+    }
 
     $log->debug( "copied instance" );
@@ -232,4 +249,5 @@
     return $uri;
 }
+
 
 sub cull {
