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:
Jeremy Fleischman 2022-09-14 07:39:04 +00:00
commit d92d97465c

View file

@ -1271,6 +1271,7 @@ class MCGCache():
def __init__(self, host, size):
self._logger = logging.getLogger(__name__)
self._host = host
self._size = size
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)
if os.path.exists(filename):
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
if size != self._size:
self._clear()