From c695c4af7f78b5b8a37251b720ec48615ed28106 Mon Sep 17 00:00:00 2001 From: "Alex \"mcmonkey\" Goodwin" <4000772+mcmonkey4eva@users.noreply.github.com> Date: Wed, 16 Oct 2024 00:35:37 -0700 Subject: [PATCH] Frontend Manager: avoid redundant gh calls for static versions (#5152) * Frontend Manager: avoid redundant gh calls for static versions * actually, removing old tmpdir isn't needed I tested - downloader code handles this case well already (also rmdir was wrong func anyway, needed shutil.rmtree if it had content) * add code comment --- app/frontend_management.py | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/frontend_management.py b/app/frontend_management.py index 9c832e46..191408ac 100644 --- a/app/frontend_management.py +++ b/app/frontend_management.py @@ -151,6 +151,15 @@ def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndPr return cls.DEFAULT_FRONTEND_PATH repo_owner, repo_name, version = cls.parse_version_string(version_string) + + if version.startswith("v"): + expected_path = str(Path(cls.CUSTOM_FRONTENDS_ROOT) / f"{repo_owner}_{repo_name}" / version.lstrip("v")) + if os.path.exists(expected_path): + logging.info(f"Using existing copy of specific frontend version tag: {repo_owner}/{repo_name}@{version}") + return expected_path + + logging.info(f"Initializing frontend: {repo_owner}/{repo_name}@{version}, requesting version details from GitHub...") + provider = provider or FrontEndProvider(repo_owner, repo_name) release = provider.get_release(version) @@ -159,16 +168,20 @@ def init_frontend_unsafe(cls, version_string: str, provider: Optional[FrontEndPr Path(cls.CUSTOM_FRONTENDS_ROOT) / provider.folder_name / semantic_version ) if not os.path.exists(web_root): + # Use tmp path until complete to avoid path exists check passing from interrupted downloads + tmp_path = web_root + ".tmp" try: - os.makedirs(web_root, exist_ok=True) + os.makedirs(tmp_path, exist_ok=True) logging.info( "Downloading frontend(%s) version(%s) to (%s)", provider.folder_name, semantic_version, - web_root, + tmp_path, ) logging.debug(release) - download_release_asset_zip(release, destination_path=web_root) + download_release_asset_zip(release, destination_path=tmp_path) + if os.listdir(tmp_path): + os.rename(tmp_path, web_root) finally: # Clean up the directory if it is empty, i.e. the download failed if not os.listdir(web_root):