From: Jeroen van der Heijden Date: Thu, 23 Apr 2020 13:20:44 +0000 (+0200) Subject: Update, only continue when at least 80 percent is successful read X-Git-Tag: archive/raspbian/2.0.44-1+rpi1~1^2~3^2~4^2~7 X-Git-Url: https://dgit.raspbian.org/?a=commitdiff_plain;h=5ea2c7857e8c5c2b3f8528b4dd7827e100d9677d;p=siridb-server.git Update, only continue when at least 80 percent is successful read --- diff --git a/src/siri/db/series.c b/src/siri/db/series.c index 8735e26d..a4802ad3 100644 --- a/src/siri/db/series.c +++ b/src/siri/db/series.c @@ -1602,17 +1602,32 @@ static int SERIES_load(siridb_t * siridb, imap_t * dropped) /* save last object, should be QP_END */ tp = qp_next(unpacker, NULL); - /* free unpacker */ - qp_unpacker_ff_free(unpacker); - if (tp != QP_END) { + double start = (double) (unpacker->end - unpacker->source); + double pos = (double) (unpacker->pt - unpacker->source); + + if (pos / start < 0.8) + { + log_critical( + "Cannot read at least 80 percent of '%s', " + "do not continue as this leads to data loss", + fn); + /* free unpacker */ + qp_unpacker_ff_free(unpacker); + return -1; + } + log_error( "Expected end of file '%s'; " "Create a backup and continue", fn); + (void) SERIES_keep_corrupt_series(siridb); } + /* free unpacker */ + qp_unpacker_ff_free(unpacker); + /* * In case of a siri_err we should not return -1; * overwrite series because the