vcs-settings: moved creation of largefiles default dirs into vcs settings view.

- couldn't find a better place to do this
- check is cheap, and moving it out from AppStart to here makes more sense
- users need to enable largefile form this view, so enforcing defaults dirs
makes most sense right here in this view.
This commit is contained in:
Marcin Kuzminski 2017-04-20 23:56:32 +02:00
parent 1ee433edf9
commit aa53b82e49
2 changed files with 29 additions and 1 deletions

View file

@ -195,9 +195,12 @@ class SettingsController(BaseController):
pyramid_settings = get_current_registry().settings
c.svn_proxy_generate_config = pyramid_settings[generate_config]
defaults = self._form_defaults()
model.create_largeobjects_dirs_if_needed(defaults['paths_root_path'])
return htmlfill.render(
render('admin/settings/settings.mako'),
defaults=self._form_defaults(),
defaults=defaults,
encoding="UTF-8",
force_defaults=False)

View file

@ -18,6 +18,7 @@
# RhodeCode Enterprise Edition, including its added features, Support services,
# and proprietary license terms, please see https://rhodecode.com/licenses/
import os
import hashlib
import logging
from collections import namedtuple
@ -775,3 +776,27 @@ class VcsSettingsModel(object):
raise ValueError(
'The given data does not contain {} key'.format(data_key))
return data_keys
def create_largeobjects_dirs_if_needed(self, repo_store_path):
"""
This is subscribed to the `pyramid.events.ApplicationCreated` event. It
does a repository scan if enabled in the settings.
"""
from rhodecode.lib.vcs.backends.hg import largefiles_store
from rhodecode.lib.vcs.backends.git import lfs_store
paths = [
largefiles_store(repo_store_path),
lfs_store(repo_store_path)]
for path in paths:
if os.path.isdir(path):
continue
if os.path.isfile(path):
continue
# not a file nor dir, we try to create it
try:
os.makedirs(path)
except Exception:
log.warning('Failed to create largefiles dir:%s', path)