From 314a9bf67c5f5b8b68543d51b14a20eda751bfb6 Mon Sep 17 00:00:00 2001 From: Vladimir Mandic Date: Thu, 18 May 2023 14:55:43 -0400 Subject: [PATCH] fix extension uninstall --- javascript/extensions.js | 2 +- modules/ui_extensions.py | 25 ++++++++++++++----------- 2 files changed, 15 insertions(+), 12 deletions(-) diff --git a/javascript/extensions.js b/javascript/extensions.js index cec762f8b..d59a7d059 100644 --- a/javascript/extensions.js +++ b/javascript/extensions.js @@ -36,7 +36,7 @@ function install_extension(button, url) { } function uninstall_extension(button, url) { - console.log('Extension uninstall:', url, decodeURIComponent(url), encodeURI(url)); + console.log('Extension uninstall:', url, JSON.stringify(url), decodeURIComponent(url), encodeURI(url)); button.disabled = 'disabled'; button.value = 'Uninstalling...'; button.innerHTML = 'uninstalling'; diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index 28c1618dc..470a3cbf1 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -192,24 +192,26 @@ def uninstall_extension(extension_path, search_text, sort_column): os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) func(path) - shared.log.info(f'Extension uninstall: {extension_path}') - ext = [extension for extension in extensions.extensions if extension.path == extension_path] + ext = [extension for extension in extensions.extensions if os.path.abspath(extension.path) == os.path.abspath(extension_path)] if len(ext) > 0 and os.path.isdir(extension_path): + found = ext[0] try: - shutil.rmtree(extension_path, ignore_errors=False, onerror=errorRemoveReadonly) + shutil.rmtree(found.path, ignore_errors=False, onerror=errorRemoveReadonly) except Exception as e: - shared.log.warning(f'Extension uninstall failed: {extension_path} {e}') - extensions.extensions = [extension for extension in extensions.extensions if extension.path != extension_path] + shared.log.warning(f'Extension uninstall failed: {found.path} {e}') + extensions.extensions = [extension for extension in extensions.extensions if os.path.abspath(found.path) != os.path.abspath(extension_path)] update_extension_list() + code = refresh_extensions_list_from_data(search_text, sort_column) + shared.log.info(f'Extension uninstalled: {found.path}') + return code, f"Extension uninstalled: {found.path} | Restart required" else: shared.log.warning(f'Extension uninstall cannot find extension: {extension_path}') - code = refresh_extensions_list_from_data(search_text, sort_column) - # return code, ext_table, message - return code, f"Extension uninstalled: {extension_path} | Restart required" + code = refresh_extensions_list_from_data(search_text, sort_column) + return code, f"Extension uninstalled failed: {extension_path}" def update_extension(extension_path, search_text, sort_column): - exts = [extension for extension in extensions.extensions if extension.path == extension_path] + exts = [extension for extension in extensions.extensions if os.path.abspath(extension.path) == os.path.abspath(extension_path)] shared.state.job_count = len(exts) for ext in exts: shared.log.debug(f'Extensions update start: {ext.name} {ext.commit_hash} {ext.commit_date}') @@ -339,10 +341,11 @@ def refresh_extensions_list_from_data(search_text, sort_column): type_code = f"""
{"SYSTEM" if ext['is_builtin'] else 'USER'}
""" version_code = f"""
{ext['version']}
""" enabled_code = f"""""" + masked_path = html.escape(path.replace('\\', '/')) if not ext['is_builtin']: - install_code = f"""""" + install_code = f"""""" if update_available: - install_code += f"""""" + install_code += f"""""" else: install_code = f"""""" tags_text = ", ".join([f"{x}" for x in tags])