From 95cb046321f620e85e6001e9ed916e478e53d5db Mon Sep 17 00:00:00 2001 From: Brandon Schneider Date: Thu, 7 Mar 2019 13:09:12 -0600 Subject: [PATCH] tkt-77710: fix(jail/fetch): Check for existence of plugin_index before second run (#2727) * fix(jail/fetch): Check for existence of plugin_index before second run The second run only succeeds because the directory would have caused an EOF, but afterwards results in duplicate creation of plugins Ticket: #77710 * *cough* --- src/middlewared/middlewared/plugins/jail.py | 24 +++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/middlewared/middlewared/plugins/jail.py b/src/middlewared/middlewared/plugins/jail.py index 6b2125044a48..c3db1a9d297e 100644 --- a/src/middlewared/middlewared/plugins/jail.py +++ b/src/middlewared/middlewared/plugins/jail.py @@ -409,6 +409,7 @@ def fetch(self, job, options): """Fetches a release or plugin.""" fetch_output = {'install_notes': []} release = options.get('release', None) + post_install = False verrors = ValidationErrors() @@ -467,13 +468,20 @@ def progress_callback(content, exception): iocage = ioc.IOCage(callback=progress_callback, silent=False) if options["name"] is not None: - # WORKAROUND until rewritten for #39653 - # We want the plugins to not prompt interactively - try: - iocage.fetch(plugin_file=True, _list=True, **options) - except Exception: - # Expected, this is to avoid it later - pass + pool = IOCJson().json_get_value('pool') + iocroot = IOCJson(pool).json_get_value('iocroot') + plugin_index = pathlib.Path( + f'{iocroot}/.plugin_index' + ) + + if not plugin_index.is_dir(): + # WORKAROUND until rewritten for #39653 + # We want the plugins to not prompt interactively + try: + iocage.fetch(plugin_file=True, _list=True, **options) + except Exception: + # Expected, this is to avoid it later + pass options["plugin_file"] = True start_msg = 'Starting plugin install' @@ -485,8 +493,6 @@ def progress_callback(content, exception): iocage.fetch(**options) if post_install and options['name'] is not None: - pool = IOCJson().json_get_value('pool') - iocroot = IOCJson(pool).json_get_value('iocroot') plugin_manifest = pathlib.Path( f'{iocroot}/.plugin_index/{options["name"]}.json' )