Skip to content

Commit

Permalink
move cache size calculation into try block
Browse files Browse the repository at this point in the history
  • Loading branch information
OliLay committed Oct 31, 2023
1 parent 02cc4d1 commit e871e3e
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions homcc/server/cache.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,19 +57,18 @@ def _evict_oldest(self):
"""
oldest_hash, oldest_path_str = self.cache.popitem(last=False)
oldest_path = Path(oldest_path_str)
oldest_size = oldest_path.stat().st_size

try:
self.current_size_bytes -= oldest_path.stat().st_size
oldest_path.unlink(missing_ok=False)
except FileNotFoundError:
logger.error(
"Tried to evict cache entry with hash '%s', but corresponding cache file at '%s' did not exist.",
"""Tried to evict cache entry with hash '%s', but corresponding cache file at '%s' did not exist.
This may lead to an invalid cache size calculation.""",
oldest_hash,
oldest_path,
)

self.current_size_bytes -= oldest_size

@staticmethod
def _create_cache_folder(root_temp_folder: Path) -> Path:
"""Creates the cache folder inside the root folder."""
Expand Down

0 comments on commit e871e3e

Please sign in to comment.