From 22920f5c511b2d206820613d939f5672767e58c8 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Tue, 9 Jul 2024 18:19:15 +0200 Subject: reset corrupted cache files (#3074) --- lib/utils/cache.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/utils/cache.py b/lib/utils/cache.py index 543aaf15..6d51ea08 100644 --- a/lib/utils/cache.py +++ b/lib/utils/cache.py @@ -2,10 +2,11 @@ # # Copyright (c) 2010 Authors # Licensed under the GNU GPL version 3.0 or later. See the file LICENSE for details. -import os import atexit import hashlib +import os import pickle +import sqlite3 import appdirs import diskcache @@ -32,10 +33,22 @@ def get_stitch_plan_cache(): if __stitch_plan_cache is None: cache_dir = os.path.join(appdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan') size_limit = global_settings['cache_size'] * 1024 * 1024 - __stitch_plan_cache = diskcache.Cache(cache_dir, size=size_limit) + try: + __stitch_plan_cache = diskcache.Cache(cache_dir, size=size_limit) + except sqlite3.DatabaseError: + # reset cache database file if it couldn't parse correctly + cache_file = os.path.join(appdirs.user_config_dir('inkstitch'), 'cache', 'stitch_plan', 'cache.db') + if os.path.exists(cache_file): + os.remove(cache_file) + __stitch_plan_cache = diskcache.Cache(cache_dir, size=size_limit) __stitch_plan_cache.size_limit = size_limit - atexit.register(__stitch_plan_cache.close) + # reset cache if warnings appear within the files + warnings = __stitch_plan_cache.check() + if warnings: + __stitch_plan_cache.clear() + + atexit.register(__stitch_plan_cache.close) return __stitch_plan_cache -- cgit v1.2.3