Update /secure/simul_efun/spare

Neue sefuns scheinen zu funktionieren, also auch den
Ersatz aktualisieren.

Change-Id: I9134bbb2a8a27e6d8d194302f19591ac66c7ec32
diff --git a/secure/simul_efun/spare/simul_efun.c b/secure/simul_efun/spare/simul_efun.c
index f27bdea..2a89fcf 100644
--- a/secure/simul_efun/spare/simul_efun.c
+++ b/secure/simul_efun/spare/simul_efun.c
@@ -829,6 +829,7 @@
   mapping save;
   mixed index, res;
   int i;
+  string oldpath;
 
   // nur Strings und 0 zulassen
   if ((!stringp(name) || !sizeof(name)) && 
@@ -839,6 +840,24 @@
          "sefun::save_object()! Argument was %O\n",name));
   }
 
+  if (stringp(name)) {
+    // abs. Pfad erzeugen. *seufz*
+    if (name[0]!='/')
+      name = "/" + name;
+    oldpath = name;
+    // automatisch in LIBDATADIR speichern
+    if (strstr(name,"/"LIBDATADIR"/") != 0) {
+      name = "/"LIBDATADIR + name;
+      // wenn das Verzeichnis nicht existiert, ggf. anlegen
+      string dir = name[0..strrstr(name,"/")-1];
+      if (file_size(dir) != FSIZE_DIR) {
+        if (mkdirp(dir) != 1)
+          raise_error("save_object(): kann Verzeichnis " + dir
+              + " nicht anlegen!");
+      }
+    }
+  }
+
   save = m_allocate(0, 2);
   properties = (mapping)previous_object()->QueryProperties();
 
@@ -862,12 +881,19 @@
   // save object!
   previous_object()->_set_save_data(save);
   // format: wie definiert in config.h
-  if (stringp(name))
+  if (stringp(name)) {
     res = funcall(bind_lambda(#'efun::save_object, previous_object()), name,
        __LIB__SAVE_FORMAT_VERSION__);
+    // wenn erfolgreich und noch nen Savefile existiert, was nicht unter
+    // /data/ liegt, wird das geloescht.
+    if (!res && oldpath
+        && file_size(oldpath+".o") >= 0)
+      rm(oldpath+".o");
+  }
   else
     res = funcall(bind_lambda(#'efun::save_object, previous_object()),
        __LIB__SAVE_FORMAT_VERSION__);
+
   previous_object()->_set_save_data(0);
 
 #ifdef IOSTATS
@@ -900,6 +926,23 @@
   int i;
   closure cl;
 
+  // Wenn name vermutlich ein Pfad (also nicht mit #x:y anfaengt)
+  if (name[0] != '#')
+  {
+    // abs. Pfad erzeugen *seufz*
+    if (name[0] != '#' && name[0]!='/')
+      name = "/" + name;
+
+    // wenn kein /data/ vorn steht, erstmal gucken, ob das Savefile unter
+    // /data/ existiert. Wenn ja, wird das geladen.
+    if (name[0]!='#' && strstr(name,"/"LIBDATADIR"/") != 0)
+    {
+      string path = "/"LIBDATADIR + name;
+      if (file_size(path + ".o") >= 0)
+        name = path;
+    }
+  }
+
   // get actual property settings (by create())
   properties = (mapping)previous_object()->QueryProperties();