Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enlarge cache based on disk size #98

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading