# HG changeset patch # User Marcin Kuzminski # Date 2017-04-20 21:56:32 # Node ID 9db59bee12251f6f2ad7870ffb9bd11a55a0b92b # Parent 7d9eb9ff2894f2f8b0a2cfb11217990c2a960acd 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. diff --git a/rhodecode/controllers/admin/settings.py b/rhodecode/controllers/admin/settings.py --- a/rhodecode/controllers/admin/settings.py +++ b/rhodecode/controllers/admin/settings.py @@ -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) diff --git a/rhodecode/model/settings.py b/rhodecode/model/settings.py --- a/rhodecode/model/settings.py +++ b/rhodecode/model/settings.py @@ -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)