Index: trunk/DataStore/scripts/dsget
===================================================================
--- trunk/DataStore/scripts/dsget	(revision 16368)
+++ trunk/DataStore/scripts/dsget	(revision 17450)
@@ -3,5 +3,5 @@
 # Copyright (C) 2006-2008  Joshua Hoblitt
 #
-# $Id: dsget,v 1.14 2008-02-08 19:30:38 eugene Exp $
+# $Id: dsget,v 1.15 2008-04-18 00:35:35 jhoblitt Exp $
 
 use strict;
@@ -83,38 +83,38 @@
     my $dirname = dirname($filename);
     if (!-d $dirname) {
-	mkpath([$dirname], 1, 0775);
+        mkpath([$dirname], 1, 0775);
     }
 
     # can we truly write to filename?
-    {
-	# open file for read/write but not create
-	my $fh;
-	if (open($fh, '+<', $filename)) {
-	    # do nothing and fall through
-	} elsif (open($fh, '>>', $filename)) {
-	    # this is the "stomp on it behavior" this probably shouldn't be the
-	    # default and it may make sense to check the md5sum/bytes count of the
-	    # files that's already in place to see if we really need to re-fetch it
-	    unlink $filename or die "can't unlink $filename: $!";
-	} else {
-	    die "can't write to $filename";
-	}
+{
+    # open file for read/write but not create
+    my $fh;
+    if (open($fh, '+<', $filename)) {
+        # do nothing and fall through
+    } elsif (open($fh, '>>', $filename)) {
+        # this is the "stomp on it behavior" this probably shouldn't be the
+        # default and it may make sense to check the md5sum/bytes count of the
+        # files that's already in place to see if we really need to re-fetch it
+        unlink $filename or die "can't unlink $filename: $!";
+    } else {
+        die "can't write to $filename";
     }
+}
 
     # for non-neb files, use the download directory for the tmp file
     $tmp = File::Temp->new(
-			   DIR         => $dirname,
-			   TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
-			   SUFFIX      => '.tmp',
-			   UNLINK      => 1,
-			   );
+               DIR         => $dirname,
+               TEMPLATE    => '.' . basename($filename) . '.XXXXXXXX',
+               SUFFIX      => '.tmp',
+               UNLINK      => 1,
+               );
 } else {
     # for neb files, use /tmp for the tmp file
     $tmp = File::Temp->new(
-			   DIR         => '/tmp',
-			   TEMPLATE    => basename($filename) . '.XXXXXXXX',
-			   SUFFIX      => '.tmp',
-			   UNLINK      => 1,
-			   );
+               DIR         => '/tmp',
+               TEMPLATE    => basename($filename) . '.XXXXXXXX',
+               SUFFIX      => '.tmp',
+               UNLINK      => 1,
+               );
 }
 
@@ -144,6 +144,15 @@
         unless defined $neb;
 
+    # XXX see comment above and not blindly stomping
+    # if the key doesn't already exist then create it
+    # if it does, delete it so that we end up on the right storage volume
+    if ($neb->stat($filename)) {
+        $neb->delete($filename)
+            or die "Nebulous can't delete key $filename";
+    }
+
     my $fh = $neb->open_create( $filename, $volume )
         or die "Nebulous can't create key $filename";
+
     open(my $src_fh, $tmpfilename) or die "can't open file $tmpfilename: $!";
 
