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
This commit is contained in:
parent
0dbba9f751
commit
c695c4af7f
|
@ -151,6 +151,15 @@ class FrontendManager:
|
|||
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 @@ class FrontendManager:
|
|||
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):
|
||||
|
|
Loading…
Reference in New Issue