Update version and continue on corrupt series.dat
authorJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 23 Apr 2020 12:56:47 +0000 (14:56 +0200)
committerJeroen van der Heijden <jeroen@transceptor.technology>
Thu, 23 Apr 2020 12:56:47 +0000 (14:56 +0200)
include/siri/version.h
src/siri/db/series.c

index e4a71f3d469c6e7309cded2317a79bbe4a234b15..9036b5b701ce83c5acb2f128e0a5760a95d8ca63 100644 (file)
@@ -15,7 +15,7 @@
  * Note that debian alpha packages should use versions like this:
  *   2.0.34-0alpha0
  */
-#define SIRIDB_VERSION_PRE_RELEASE "-alpha-0"
+#define SIRIDB_VERSION_PRE_RELEASE "-alpha-1"
 
 #ifndef NDEBUG
 #define SIRIDB_VERSION_BUILD_RELEASE "+debug"
index edb835864b94d86054db95f484e5ced5b068ab4d..8735e26da24af832dfcef32ee5a0f8c229b563b0 100644 (file)
@@ -32,6 +32,7 @@
 #include <xpath/xpath.h>
 
 #define SIRIDB_SERIES_FN "series.dat"
+#define SIRIDB_CORRUPT_FN "corrupt_series.dat"
 #define SIRIDB_DROPPED_FN ".dropped"
 #define SIRIDB_MAX_SERIES_ID_FN ".max_series_id"
 #define SIRIDB_SERIES_SCHEMA 1
@@ -1514,6 +1515,25 @@ static int SERIES_read_dropped(siridb_t * siridb, imap_t * dropped)
     return rc;
 }
 
+static int SERIES_keep_corrupt_series(siridb_t * siridb)
+{
+    int rc;
+    siridb_misc_get_fn(series_fn, siridb->dbpath, SIRIDB_SERIES_FN)
+    siridb_misc_get_fn(corrupt_fn, siridb->dbpath, SIRIDB_CORRUPT_FN)
+
+    (void) unlink(corrupt_fn);
+    rc = rename(series_fn, corrupt_fn);
+    if (rc == 0)
+    {
+        log_warning("Keep previous '%s' as '%s'", series_fn, corrupt_fn);
+    }
+    else
+    {
+        log_error("Cannot rename '%s' to '%s'", series_fn, corrupt_fn);
+    }
+    return rc;
+}
+
 static int SERIES_load(siridb_t * siridb, imap_t * dropped)
 {
     qp_unpacker_t * unpacker;
@@ -1587,12 +1607,15 @@ static int SERIES_load(siridb_t * siridb, imap_t * dropped)
 
     if (tp != QP_END)
     {
-        log_critical("Expected end of file '%s'", fn);
-        return -1;
+        log_error(
+                "Expected end of file '%s'; "
+                "Create a backup and continue", fn);
+        (void) SERIES_keep_corrupt_series(siridb);
     }
 
     /*
-     * In case of a siri_err we should not overwrite series because the
+     * In case of a siri_err we should not         return -1;
+     * overwrite series because the
      * file then might be incomplete.
      */
     if (siri_err || SERIES_save(siridb))