Index: /branches/neb_distrib_20081210/Nebulous/bin/neb-replicate
===================================================================
--- /branches/neb_distrib_20081210/Nebulous/bin/neb-replicate	(revision 23690)
+++ /branches/neb_distrib_20081210/Nebulous/bin/neb-replicate	(revision 23691)
@@ -45,18 +45,28 @@
     unless defined $neb;
 
-# XXX if replicate fails, we should still set user.copies (if requested)
-for (my $i = 0; $i < $copies; $i++) {
-    if (defined $volume) {
-        $neb->replicate($key, $volume)
-            or die "failed to replicate Nebulous key: $key";
-    } else {
-        $neb->replicate($key)
-            or die "failed to replicate Nebulous key: $key";
+# if replicate fails, we should still set user.copies (if requested)
+my $replication_problem;
+eval {
+    for (my $i = 0; $i < $copies; $i++) {
+        if (defined $volume) {
+            $neb->replicate($key, $volume)
+                or die "failed to replicate Nebulous key: $key";
+        } else {
+            $neb->replicate($key)
+                or die "failed to replicate Nebulous key: $key";
+        }
     }
+};
+if ($@) {
+    warn $@;
+    $replication_problem = 1;
 }
 
-if (defined $set_copies && $set_copies) {
-    write_xattrs($neb, $key, "user.copies:$set_copies") or die;
+if ($set_copies) {
+    $neb->setxattr($key, "user.copies", $copies, "replace")
+        or die $neb->err;
 }
+
+exit(32) if defined $replication_problem;
 
 __END__
@@ -71,5 +81,5 @@
 
     neb-replicate [--server <URL>] [--volume <volume name>]
-                  [--copies <n>] <key>
+                  [--copies <n>] [--set_copies <n>] <key>
 
 =head1 DESCRIPTION
@@ -98,5 +108,11 @@
 The number of new replications to create.
 
-Optional.  Defaults to 0.
+Optional.  Defaults to 1.
+
+=item * --set_copies|c <n>
+
+Set the C<user.copies> xattr for this storage object to C<<n>>.
+
+Optional.
 
 =back
