From 943e7bcec5a39bfe874f97a7f2b25c8ea0265e52 Mon Sep 17 00:00:00 2001 From: Julianne Swinoga Date: Sun, 26 Nov 2023 12:49:06 -0500 Subject: [PATCH] When removing previously downloaded FW, try to make any problem files writable and then try deleting again. Fixes #33 --- OATFWGUI/gui_logic.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/OATFWGUI/gui_logic.py b/OATFWGUI/gui_logic.py index 7167918..66e19e0 100644 --- a/OATFWGUI/gui_logic.py +++ b/OATFWGUI/gui_logic.py @@ -4,6 +4,8 @@ import zipfile import json import shutil +import os +import stat from typing import List, Optional from pathlib import Path @@ -64,11 +66,17 @@ def download_fw(zip_url: str) -> Path: def extract_fw(zipfile_name: Path) -> Path: + def remove_readonly(func, path, excinfo): + # Windows has a problem with deleting some git files + log.debug(f'Problem removing {path}, attempting to make writable') + os.chmod(path, stat.S_IWRITE) + func(path) + # For Windows path length reasons, keep the firmware folder name short fw_dir = Path(get_install_dir(), 'OATFW') if fw_dir.exists(): log.info(f'Removing previously downloaded FW from {fw_dir}') - shutil.rmtree(fw_dir, ignore_errors=True) + shutil.rmtree(fw_dir, onerror=remove_readonly) log.info(f'Extracting FW from {zipfile_name}') with zipfile.ZipFile(zipfile_name, 'r') as zip_ref: