mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-11-15 03:30:29 +03:00
git_mirror_size_limit config option to set max git mirror size
GitHub and GitLab have some kinds of limits on how big a git repo can be, this makes that option configurable. This also is very useful for tests.
This commit is contained in:
parent
4fa11ef4fc
commit
e76a0c9d6a
5 changed files with 100 additions and 4 deletions
|
|
@ -148,6 +148,7 @@ default_config = {
|
|||
'archive_description': _('These are the apps that have been archived from the main repo.'),
|
||||
'archive_older': 0,
|
||||
'lint_licenses': fdroidserver.lint.APPROVED_LICENSES,
|
||||
'git_mirror_size_limit': 10000000000,
|
||||
}
|
||||
|
||||
|
||||
|
|
@ -354,9 +355,31 @@ def read_config(opts, config_file='config.py'):
|
|||
raise TypeError(_('only accepts strings, lists, and tuples'))
|
||||
config['servergitmirrors'] = roots
|
||||
|
||||
limit = config['git_mirror_size_limit']
|
||||
config['git_mirror_size_limit'] = parse_human_readable_size(limit)
|
||||
|
||||
return config
|
||||
|
||||
|
||||
def parse_human_readable_size(size):
|
||||
units = {
|
||||
'b': 1,
|
||||
'kb': 1000, 'mb': 1000**2, 'gb': 1000**3, 'tb': 1000**4,
|
||||
'kib': 1024, 'mib': 1024**2, 'gib': 1024**3, 'tib': 1024**4,
|
||||
}
|
||||
try:
|
||||
return int(float(size))
|
||||
except (ValueError, TypeError):
|
||||
if type(size) != str:
|
||||
raise ValueError(_('Could not parse size "{size}", wrong type "{type}"')
|
||||
.format(size=size, type=type(size)))
|
||||
s = size.lower().replace(' ', '')
|
||||
m = re.match(r'^(?P<value>[0-9][0-9.]+) *(?P<unit>' + r'|'.join(units.keys()) + r')$', s)
|
||||
if not m:
|
||||
raise ValueError(_('Not a valid size definition: "{}"').format(size))
|
||||
return int(float(m.group("value")) * units[m.group("unit")])
|
||||
|
||||
|
||||
def assert_config_keystore(config):
|
||||
"""Check weather keystore is configured correctly and raise exception if not."""
|
||||
|
||||
|
|
|
|||
|
|
@ -356,11 +356,15 @@ def update_servergitmirrors(servergitmirrors, repo_section):
|
|||
# github/gitlab use bare git repos, so only count the .git folder
|
||||
# test: generate giant APKs by including AndroidManifest.xml and and large
|
||||
# file from /dev/urandom, then sign it. Then add those to the git repo.
|
||||
if os.path.isdir(dotgit) and _get_size(dotgit) > 1000000000:
|
||||
logging.warning('Deleting git-mirror history, repo is too big (1 gig max)')
|
||||
dotgit_size = _get_size(dotgit)
|
||||
dotgit_over_limit = dotgit_size > config['git_mirror_size_limit']
|
||||
if os.path.isdir(dotgit) and dotgit_over_limit:
|
||||
logging.warning(_('Deleting git-mirror history, repo is too big ({size} max {limit})')
|
||||
.format(size=dotgit_size, limit=config['git_mirror_size_limit']))
|
||||
shutil.rmtree(dotgit)
|
||||
if options.no_keep_git_mirror_archive and _get_size(dotgit) > 1000000000:
|
||||
logging.warning('Deleting archive, repo is too big (1 gig max)')
|
||||
if options.no_keep_git_mirror_archive and dotgit_over_limit:
|
||||
logging.warning(_('Deleting archive, repo is too big ({size} max {limit})')
|
||||
.format(size=dotgit_size, limit=config['git_mirror_size_limit']))
|
||||
archive_path = os.path.join(git_mirror_path, 'fdroid', 'archive')
|
||||
shutil.rmtree(archive_path, ignore_errors=True)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue