From 19f9fc95fdf4a2f58ff60d24b04d884544d6fb86 Mon Sep 17 00:00:00 2001 From: awsr <43862868+awsr@users.noreply.github.com> Date: Sat, 8 Nov 2025 14:56:04 -0800 Subject: [PATCH] Improve extension url handling --- modules/ui_extensions.py | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) diff --git a/modules/ui_extensions.py b/modules/ui_extensions.py index f5f81229d..d361214ce 100644 --- a/modules/ui_extensions.py +++ b/modules/ui_extensions.py @@ -124,14 +124,11 @@ def check_updates(_id_task, disable_list, search_text, sort_column): return create_html(search_text, sort_column), "Extension update complete | Restart required" -def normalize_git_url(url): - if url is None: - return "" - url = url.replace(".git", "") - return url +def normalize_git_url(url: str | None) -> str: + return '' if url is None else url.removesuffix('.git') -def install_extension_from_url(dirname, url, branch_name, search_text, sort_column): +def install_extension_from_url(dirname, url: str | None, branch_name, search_text, sort_column): if shared.cmd_opts.disable_extension_access: shared.log.error('Extension: apply changes disallowed because public access is enabled and insecure is not specified') return ['', ''] @@ -139,19 +136,15 @@ def install_extension_from_url(dirname, url, branch_name, search_text, sort_colu shared.log.error('Extension: url is not specified') return ['', ''] if dirname is None or dirname == "": - *parts, last_part = url.split('/') # pylint: disable=unused-variable - last_part = normalize_git_url(last_part) - dirname = last_part + dirname = normalize_git_url(url.split('/')[-1]) target_dir = os.path.join(extensions.extensions_dir, dirname) shared.log.info(f'Installing extension: {url} into {target_dir}') if os.path.exists(target_dir): shared.log.error(f'Extension: path="{target_dir}" directory already exists') return ['', ''] - normalized_url = normalize_git_url(url) - assert len([x for x in extensions.extensions if normalize_git_url(x.remote) == normalized_url]) == 0, 'Extension with this URL is already installed' + url = normalize_git_url(url) + assert len([x for x in extensions.extensions if normalize_git_url(x.remote) == url]) == 0, 'Extension with this URL is already installed' tmpdir = os.path.join(paths.data_path, "tmp", dirname) - if url.endswith('.git'): - url = url.replace('.git', '') try: import git shutil.rmtree(tmpdir, True)