# HG changeset patch # User Marcin Kuzminski # Date 2017-04-18 15:05:31 # Node ID a988196289008437aaff20cd0439191e0362cbac # Parent 48e9c86bc24fc6743f64de861ebb2e08bb8db8f5 app: ensure largefile dirs are created on application startup. diff --git a/rhodecode/config/middleware.py b/rhodecode/config/middleware.py --- a/rhodecode/config/middleware.py +++ b/rhodecode/config/middleware.py @@ -54,7 +54,7 @@ from rhodecode.lib.plugins.utils import from rhodecode.lib.utils2 import aslist as rhodecode_aslist from rhodecode.subscribers import ( scan_repositories_if_enabled, write_metadata_if_needed, - write_js_routes_if_enabled) + write_js_routes_if_enabled, create_largeobjects_dirs_if_needed) log = logging.getLogger(__name__) @@ -303,6 +303,7 @@ def includeme(config): settings['default_locale_name'] = settings.get('lang', 'en') # Add subscribers. + config.add_subscriber(create_largeobjects_dirs_if_needed, ApplicationCreated) config.add_subscriber(scan_repositories_if_enabled, ApplicationCreated) config.add_subscriber(write_metadata_if_needed, ApplicationCreated) config.add_subscriber(write_js_routes_if_enabled, ApplicationCreated) diff --git a/rhodecode/subscribers.py b/rhodecode/subscribers.py --- a/rhodecode/subscribers.py +++ b/rhodecode/subscribers.py @@ -229,6 +229,33 @@ def write_js_routes_if_enabled(event): f.write(jsroutes_file_content) +def create_largeobjects_dirs_if_needed(event): + """ + This is subscribed to the `pyramid.events.ApplicationCreated` event. It + does a repository scan if enabled in the settings. + """ + from rhodecode.lib.utils import get_rhodecode_base_path + from rhodecode.lib.vcs.backends.hg import largefiles_store + from rhodecode.lib.vcs.backends.git import lfs_store + + repo_store_path = get_rhodecode_base_path() + + 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) + + class Subscriber(object): """ Base class for subscribers to the pyramid event system.