Add debug out to Browser Cache cache dir checking #1341

This commit is contained in:
Jim Miller 2026-05-04 15:04:51 -05:00
parent 8ee0a6e898
commit 59796ff537
4 changed files with 15 additions and 1 deletions

View file

@ -40,6 +40,7 @@ class BrowserCache(object):
getConfigList_fn)
if self.browser_cache_impl is not None:
break
logger.debug("Not using Browser Cache Class %s"%browser_cache_class)
if self.browser_cache_impl is None:
raise BrowserCacheException("%s is not set, or directory does not contain a known browser cache type: '%s'"%
(CACHE_DIR_CONFIG,getConfig_fn(CACHE_DIR_CONFIG)))

View file

@ -90,18 +90,23 @@ class BlockfileCache(BaseChromiumCache):
def is_cache_dir(cache_dir):
"""Return True only if a directory is a valid Cache for this class"""
if not os.path.isdir(cache_dir):
logger.debug("Cache dir not found")
return False
index_path = os.path.join(cache_dir, "index")
if not os.path.isfile(index_path):
logger.debug("index file not found")
return False
with share_open(index_path, 'rb') as index_file:
if struct.unpack('I', index_file.read(4))[0] != INDEX_MAGIC_NUMBER:
logger.debug("index file failed magic number check")
return False
data0_path = os.path.join(cache_dir, "data_0")
if not os.path.isfile(data0_path):
logger.debug("data_0 file not found")
return False
with share_open(data0_path, 'rb') as data0_file:
if struct.unpack('I', data0_file.read(4))[0] != BLOCK_MAGIC_NUMBER:
logger.debug("data_0 failed magic number check")
return False
return True

View file

@ -68,6 +68,7 @@ class FirefoxCache2(BaseBrowserCache):
"""Return True only if a directory is a valid Cache for this class"""
# logger.debug("\n\n1Starting cache check\n\n")
if not os.path.isdir(cache_dir):
logger.debug("Cache dir not found")
return False
## check at least one entry file exists.
for en_fl in glob.iglob(os.path.join(cache_dir, 'entries', '????????????????????????????????????????')):
@ -75,6 +76,7 @@ class FirefoxCache2(BaseBrowserCache):
k = _validate_entry_file(en_fl)
if k is not None:
return True
logger.debug("No valid cache files found")
return False
def make_keys(self,url):

View file

@ -76,15 +76,19 @@ class SimpleCache(BaseChromiumCache):
def is_cache_dir(cache_dir):
"""Return True only if a directory is a valid Cache for this class"""
if not os.path.isdir(cache_dir):
logger.debug("Cache dir not found")
return False
index_file = os.path.join(cache_dir, "index")
if not (os.path.isfile(index_file) and os.path.getsize(index_file) == 24):
logger.debug("index file not found or wrong size(%s)"%os.path.getsize(index_file))
return False
real_index_file = os.path.join(cache_dir, "index-dir", "the-real-index")
if not os.path.isfile(real_index_file):
logger.debug("real_index_file not found")
return False
with share_open(real_index_file, 'rb') as index_file:
if struct.unpack('QQ', index_file.read(16))[1] != THE_REAL_INDEX_MAGIC_NUMBER:
logger.debug("real_index_file failed magic number check")
return False
try:
# logger.debug("\n\nStarting cache check\n\n")
@ -92,9 +96,11 @@ class SimpleCache(BaseChromiumCache):
k = _validate_entry_file(en_fl)
if k is not None:
return True
except SimpleCacheException:
except SimpleCacheException as sce:
# raise
logger.debug(sce)
return False
logger.debug("No valid cache files found")
return False
def get_data_key_impl(self, url, key):