Skip to content

Commit

Permalink
Merge pull request #98 from HebaruSan/fix/cache-limit
Browse files Browse the repository at this point in the history
Enlarge cache based on disk size
  • Loading branch information
HebaruSan authored Jul 27, 2024
2 parents 55b9f0f + 750575c commit f4845f7
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions ckan_meta_tester/dummy_game_instance.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import logging
from pathlib import Path
from shutil import rmtree, copy
from shutil import rmtree, copy, disk_usage
from subprocess import run
from types import TracebackType
from typing import Type, List
Expand Down Expand Up @@ -43,8 +43,13 @@ def __enter__(self) -> 'DummyGameInstance':
logging.debug('Setting cache location to %s', self.cache_path.absolute())
run(['mono', self.ckan_exe, 'cache', 'set', self.cache_path.absolute(), '--headless'],
capture_output=self.capture)
logging.debug('Setting cache limit to %s', 5000)
run(['mono', self.ckan_exe, 'cache', 'setlimit', '5000'],
# Free space plus existing cache minus 1 GB padding
cache_mbytes = max(5000,
(((disk_usage(self.cache_path)[2] if self.cache_path.is_dir() else 0)
+ sum(f.stat().st_size for f in self.cache_path.rglob('*'))
) // 1024 // 1024 - 1024))
logging.debug('Setting cache limit to %s', cache_mbytes)
run(['mono', self.ckan_exe, 'cache', 'setlimit', str(cache_mbytes)],
capture_output=self.capture)
logging.debug('Adding repo %s', self.addl_repo.as_uri())
run(['mono', self.ckan_exe, 'repo', 'add', 'local', self.addl_repo.as_uri()],
Expand Down

0 comments on commit f4845f7

Please sign in to comment.