From fad55616aa92072f453dd9d7909150f04f8538d7 Mon Sep 17 00:00:00 2001 From: Jeroen van der Heijden Date: Thu, 23 Apr 2020 14:56:47 +0200 Subject: [PATCH] Update version and continue on corrupt series.dat --- include/siri/version.h | 2 +- src/siri/db/series.c | 29 ++++++++++++++++++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/include/siri/version.h b/include/siri/version.h index e4a71f3d..9036b5b7 100644 --- a/include/siri/version.h +++ b/include/siri/version.h @@ -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" diff --git a/src/siri/db/series.c b/src/siri/db/series.c index edb83586..8735e26d 100644 --- a/src/siri/db/series.c +++ b/src/siri/db/series.c @@ -32,6 +32,7 @@ #include #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)) -- 2.30.2