Merge branch 'dont-assume-cache-size-is-valid' into 'main'
Don't assume that `size` file is valid See merge request coderkun/mcg!3
This commit is contained in:
commit
d92d97465c
1 changed files with 6 additions and 1 deletions
|
|
@ -1271,6 +1271,7 @@ class MCGCache():
|
||||||
|
|
||||||
|
|
||||||
def __init__(self, host, size):
|
def __init__(self, host, size):
|
||||||
|
self._logger = logging.getLogger(__name__)
|
||||||
self._host = host
|
self._host = host
|
||||||
self._size = size
|
self._size = size
|
||||||
self._dirname = os.path.expanduser(os.path.join(MCGCache.DIRNAME, host))
|
self._dirname = os.path.expanduser(os.path.join(MCGCache.DIRNAME, host))
|
||||||
|
|
@ -1290,7 +1291,11 @@ class MCGCache():
|
||||||
filename = os.path.join(self._dirname, MCGCache.SIZE_FILENAME)
|
filename = os.path.join(self._dirname, MCGCache.SIZE_FILENAME)
|
||||||
if os.path.exists(filename):
|
if os.path.exists(filename):
|
||||||
with open(filename, 'r') as f:
|
with open(filename, 'r') as f:
|
||||||
size = int(f.readline())
|
try:
|
||||||
|
size = int(f.readline())
|
||||||
|
except:
|
||||||
|
self._logger.warning("invalid cache file: %s, deleting file", filename, exc_info=True)
|
||||||
|
size = None
|
||||||
# Clear cache if size has changed
|
# Clear cache if size has changed
|
||||||
if size != self._size:
|
if size != self._size:
|
||||||
self._clear()
|
self._clear()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue