From 14286b381b12034140768800c7ba10baa7c3b334 Mon Sep 17 00:00:00 2001 From: Daniel Silverstone Date: Mon, 24 Feb 2020 21:01:58 +0000 Subject: fs_backing_store: Remove cache on failure to init If we fail to init the control file for reasons other than it not being found, we blow away the cache in its entirety and then try again. We warn if the removal fails, but carry on regardless since right now the worst that'll happen is that we'll end up with more on disk than we know about in the cache. Signed-off-by: Daniel Silverstone --- content/fs_backing_store.c | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/content/fs_backing_store.c b/content/fs_backing_store.c index ff1c26559..458866c62 100644 --- a/content/fs_backing_store.c +++ b/content/fs_backing_store.c @@ -62,7 +62,7 @@ #define DEFAULT_ENTRY_SIZE 16 /** Backing store file format version */ -#define CONTROL_VERSION 201 +#define CONTROL_VERSION 202 /** Number of milliseconds after a update before control data maintenance is performed */ #define CONTROL_MAINT_TIME 10000 @@ -1461,8 +1461,22 @@ initialise(const struct llcache_store_parameters *parameters) /* read store control and create new if required */ ret = read_control(newstate); if (ret != NSERROR_OK) { - NSLOG(netsurf, ERROR, "read control failed %s", - messages_get_errorcode(ret)); + if (ret == NSERROR_NOT_FOUND) { + NSLOG(netsurf, INFO, "cache control file not found, making fresh"); + } else { + NSLOG(netsurf, ERROR, "read control failed %s", + messages_get_errorcode(ret)); + ret = netsurf_recursive_rm(newstate->path); + if (ret != NSERROR_OK) { + NSLOG(netsurf, WARNING, "Error `%s` while removing `%s`", + messages_get_errorcode(ret), newstate->path); + NSLOG(netsurf, WARNING, "Unable to clean up partial cache state."); + NSLOG(netsurf, WARNING, "Funky behaviour may ensue."); + } else { + NSLOG(netsurf, INFO, "Successfully removed old cache from `%s`", + newstate->path); + } + } ret = write_control(newstate); if (ret == NSERROR_OK) { unlink_entries(newstate); -- cgit v1.2.3