Index: /trunk/Nebulous-Server/Changes
===================================================================
--- /trunk/Nebulous-Server/Changes	(revision 13227)
+++ /trunk/Nebulous-Server/Changes	(revision 13228)
@@ -2,4 +2,5 @@
 
 0.05
+    - fix a nasty logic bug in Nebulous::Client->replicate()
     - break 1:1 relationship between key names and on disk file names
     - overhaul Nebulous::Client->cull()
Index: /trunk/Nebulous/Changes
===================================================================
--- /trunk/Nebulous/Changes	(revision 13227)
+++ /trunk/Nebulous/Changes	(revision 13228)
@@ -2,4 +2,5 @@
 
 0.05
+    - fix a nasty logic bug in Nebulous::Client->replicate()
     - break 1:1 relationship between key names and on disk file names
     - overhaul Nebulous::Client->cull()
Index: /trunk/Nebulous/lib/Nebulous/Client.pm
===================================================================
--- /trunk/Nebulous/lib/Nebulous/Client.pm	(revision 13227)
+++ /trunk/Nebulous/lib/Nebulous/Client.pm	(revision 13228)
@@ -1,5 +1,5 @@
 # Copyright (c) 2004  Joshua Hoblitt
 #
-# $Id: Client.pm,v 1.30 2007-05-03 03:21:28 jhoblitt Exp $
+# $Id: Client.pm,v 1.31 2007-05-04 03:10:17 jhoblitt Exp $
 
 package Nebulous::Client;
@@ -183,4 +183,16 @@
     $log->debug( "entered - @_" );
 
+    # We have to open the instance that weren't going to copy from first.  If
+    # we don't do this, it's possible that open will find & open the new
+    # instance that we're in the process of creating
+    my $fh  = $self->open( $key, 'read' );
+    unless ( $fh ) {
+        $log->debug( "can't open $key" );
+        $log->debug( "leaving" );
+
+        return undef;
+    }
+
+    # ask the server for a new instance attached to our key
     my $response = $self->{ 'server' }->replicate_object( $key, @params );
     if ( $response->fault ) {
@@ -192,17 +204,9 @@
 
     my $res = $response->result;
-    $log->debug( "server respone $res" );
+    $log->debug( "server response $res" );
 
     my $uri = URI->new($res);
     my $filename = $uri->file;
     $log->debug( "local filename is $filename" );
-
-    my $fh  = $self->open( $key, 'read' );
-    unless ( $fh ) {
-        $log->debug( "can't open $key" );
-        $log->debug( "leaving" );
-
-        return undef;
-    }
 
     my $new_fh;
