]> git.pond.sub.org Git - empserver/commitdiff
Fix empdump not to touch plane file when import fails
authorMarkus Armbruster <armbru@pond.sub.org>
Sun, 22 May 2011 05:46:57 +0000 (07:46 +0200)
committerMarkus Armbruster <armbru@pond.sub.org>
Sat, 25 Jun 2011 15:05:12 +0000 (17:05 +0200)
pln_zap_transient_flags() fixes up planes stuck in the air (commit
7ca4f412, v4.3.12).  Since commit 4e9e58bf (v4.3.14), it writes back
the fixed planes.  This is wrong for empdump.

empdump should touch data only on successful import.  When it fails
because ef_verify() fails, and any planes are found stuck in the air,
the plane file gets rewritten.

Make parameter ef_verify() take parameter may_put to let empdump
suppress the plane write-back.  The plane file still get written out
on successful import, along with the other imported game state.

include/file.h
src/lib/common/ef_verify.c
src/lib/subs/fileinit.c
src/util/empdump.c

index 73816c6f9de66f44a98a2fd738619be941064e5c..a4e2a7e390e866e01313b50b3082badf91c258f8 100644 (file)
@@ -225,7 +225,7 @@ extern int ef_nelem(int);
 extern int ef_flags(int);
 extern int ef_byname(char *);
 extern int ef_byname_from(char *, int *);
-extern int ef_verify(void);
+extern int ef_verify(int);
 extern int ef_elt_byname(int, char *);
 
 extern struct empfile empfile[EF_MAX + 1];
index a288cb4fd2dff30248a3a25d6ca93e222ba80b6f..139d04315a9d411f117ac25c4d6f77e5bca45e47 100644 (file)
@@ -194,7 +194,7 @@ verify_row(int type, int row)
 }
 
 static void
-pln_zap_transient_flags(void)
+pln_zap_transient_flags(int may_put)
 {
     int i;
     struct plnstr *pp;
@@ -216,12 +216,18 @@ pln_zap_transient_flags(void)
             */
        }
     }
-    if (dirty)
+    if (dirty && may_put)
        ef_flush(EF_PLANE);     /* pretty wasteful */
 }
 
+/*
+ * Verify game state and configuration are sane.
+ * Correct minor problems, but write corrections to backing files only
+ * if MAY_PUT is non-zero.
+ * Return -1 if uncorrected problems remain, else 0.
+ */
 int
-ef_verify(void)
+ef_verify(int may_put)
 {
     struct empfile *ep;
     int retval = 0;
@@ -248,6 +254,6 @@ ef_verify(void)
        }
     }
 
-    pln_zap_transient_flags();
+    pln_zap_transient_flags(may_put);
     return retval;
 }
index 4664b5e3661607fd11c852ef19d30d513aead789..8e7580127912159fa9614fd7035cc0fc209186af 100644 (file)
@@ -72,7 +72,7 @@ ef_init_srv(void)
 
     nsc_init();
     ef_open_srv();
-    if (ef_verify() < 0)
+    if (ef_verify(1) < 0)
        exit(EXIT_FAILURE);
     global_init();
     unit_cargo_init();
index 1e9296828be0b8d3f140c86b521a5e6a9fdf8f6f..652beb0060765952f517993a66ad0a828f488bbd 100644 (file)
@@ -150,7 +150,7 @@ main(int argc, char *argv[])
            exit(1);
     }
 
-    if (ef_verify() < 0)
+    if (ef_verify(0) < 0)
        exit(1);
 
     /* export to stdout */