Index: /trunk/Nebulous/nebclient/src/nebclient.c
===================================================================
--- /trunk/Nebulous/nebclient/src/nebclient.c	(revision 20340)
+++ /trunk/Nebulous/nebclient/src/nebclient.c	(revision 20341)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: nebclient.c,v 1.52 2008-10-16 23:53:01 jhoblitt Exp $
+ * $Id: nebclient.c,v 1.53 2008-10-23 07:44:43 bills Exp $
  */
 
@@ -247,5 +247,5 @@
 
     locations = nebFindInstances(server, key, NULL);
-    if (!locations) {
+    if (!locations || locations->n <= 1) {
         nebSetErr(server, "can not cull - not enough instances");
 
@@ -260,4 +260,13 @@
 
     nebObjectInstancesFree(locations);
+
+    return true;
+}
+
+bool nebCullAllButOne(nebServer *server, const char *key)
+{
+    while (nebCull(server, key)) {
+        ;
+    }
 
     return true;
Index: /trunk/Nebulous/nebclient/src/nebclient.h
===================================================================
--- /trunk/Nebulous/nebclient/src/nebclient.h	(revision 20340)
+++ /trunk/Nebulous/nebclient/src/nebclient.h	(revision 20341)
@@ -4,5 +4,5 @@
  * Copyright (C) 2005  Joshua Hoblitt
  *
- * $Id: nebclient.h,v 1.34 2008-10-16 23:53:01 jhoblitt Exp $
+ * $Id: nebclient.h,v 1.35 2008-10-23 07:44:43 bills Exp $
  */
 
@@ -120,4 +120,14 @@
 );
 
+/** Removes all but one instance from a storage object
+ *
+ * @return true on success
+ */
+
+bool nebCullAllButOne(
+    nebServer *server,                  ///< nebServer object
+    const char *key                     ///< storage object key (name)
+);
+
 /** Trys to acquire a lock on a storage object
  *
Index: /trunk/psModules/src/config/pmConfig.c
===================================================================
--- /trunk/psModules/src/config/pmConfig.c	(revision 20340)
+++ /trunk/psModules/src/config/pmConfig.c	(revision 20341)
@@ -1604,6 +1604,5 @@
         nebServer *server = nebServerAlloc(neb_server);
         if (!server) {
-            psError(PM_ERR_SYS, true, "failed to create a nebServer object: %s", nebErr(server));
-            nebServerFree(server);
+            psError(PM_ERR_SYS, true, "failed to create a nebServer object.");
             return NULL;
         }
@@ -1626,4 +1625,18 @@
                 return NULL;
             }
+        } else if (create || trunc) {
+            // object exists and it looks like the caller intends to write to it
+            // delete all but one instance
+            if (!nebCullAllButOne(server,filename)) {
+                psError(PM_ERR_SYS, true, "failed to cull instances of existing nebulous file: %s\n%s", 
+                    filename, nebErr(server));
+                return NULL;
+            }
+            // we don't know which instances got culled so get the instance again
+            if (!(nebfile = nebFind(server, filename))) {
+                psError(PM_ERR_SYS, true, "failed to find instance of existing nebulous file: %s\n%s", 
+                    filename, nebErr(server));
+                return NULL;
+            }
         }
 
