summaryrefslogtreecommitdiff
path: root/lib/utils/cache.py
diff options
context:
space:
mode:
authorKaalleen <36401965+kaalleen@users.noreply.github.com>2024-07-09 18:19:15 +0200
committerGitHub <noreply@github.com>2024-07-09 18:19:15 +0200
commit22920f5c511b2d206820613d939f5672767e58c8 (patch)
treefaf8019bf8babd9425c84760a70288e2767b132d /lib/utils/cache.py
parent4644c119495e175e909096d4e947dbb9e5f8234a (diff)
reset corrupted cache files (#3074)
Diffstat (limited to 'lib/utils/cache.py')
-rw-r--r--lib/utils/cache.py19
1 files 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