From 7eaa4189ae86285ba07795f51b6fd0a2e9c868b4 Mon Sep 17 00:00:00 2001 From: FredWuCZ Date: Thu, 17 Oct 2024 19:15:37 +0800 Subject: [PATCH] Fix unzip --- desktop_env/providers/docker/manager.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/desktop_env/providers/docker/manager.py b/desktop_env/providers/docker/manager.py index c06402a..4a7abde 100644 --- a/desktop_env/providers/docker/manager.py +++ b/desktop_env/providers/docker/manager.py @@ -95,11 +95,12 @@ def _download_vm(vms_dir: str): logger.info("Download succeeds.") break # Download completed successfully - # Unzip the downloaded file - logger.info("Unzipping the downloaded file...☕️") - with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref: - zip_ref.extractall(vms_dir) - logger.info("Files have been successfully extracted to the directory: " + str(vms_dir)) + if downloaded_file_name.endswith(".zip"): + # Unzip the downloaded file + logger.info("Unzipping the downloaded file...☕️") + with zipfile.ZipFile(downloaded_file_path, 'r') as zip_ref: + zip_ref.extractall(vms_dir) + logger.info("Files have been successfully extracted to the directory: " + str(vms_dir)) class DockerVMManager(VMManager): def __init__(self, registry_path=""): @@ -130,8 +131,12 @@ class DockerVMManager(VMManager): elif os_type == "Windows": URL = WINDOWS_X86_URL DOWNLOADED_FILE_NAME = URL.split('/')[-1] + if DOWNLOADED_FILE_NAME.endswith(".zip"): - DOWNLOADED_FILE_NAME = DOWNLOADED_FILE_NAME[:-4] - if not os.path.exists(os.path.join(VMS_DIR, DOWNLOADED_FILE_NAME)): + vm_name = DOWNLOADED_FILE_NAME[:-4] + else: + vm_name = DOWNLOADED_FILE_NAME + + if not os.path.exists(os.path.join(VMS_DIR, vm_name)): _download_vm(VMS_DIR) - return os.path.join(VMS_DIR, DOWNLOADED_FILE_NAME) \ No newline at end of file + return os.path.join(VMS_DIR, vm_name) \ No newline at end of file