Update extension uninstall if read-only

This commit is contained in:
awsr
2025-11-21 16:15:52 -08:00
parent b4ba041aa5
commit e8b1797929
+4 -5
View File
@@ -191,11 +191,10 @@ def install_extension(extension_to_install, search_text, sort_column):
def uninstall_extension(extension_path, search_text, sort_column):
def errorRemoveReadonly(func, path, exc):
def excRemoveReadonly(func, path, exc: Exception):
import stat
excvalue = exc[1]
shared.log.debug(f'Exception during cleanup: {func} {path} {excvalue.strerror}')
if func in (os.rmdir, os.remove, os.unlink) and excvalue.errno == errno.EACCES:
shared.log.debug(f'Exception during cleanup: {func} {path} {type(exc).__name__}')
if func in (os.rmdir, os.remove, os.unlink) and isinstance(exc, PermissionError):
shared.log.debug(f'Retrying cleanup: {path}')
os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
func(path)
@@ -204,7 +203,7 @@ def uninstall_extension(extension_path, search_text, sort_column):
if len(found) > 0 and os.path.isdir(extension_path):
found = found[0]
try:
shutil.rmtree(found.path, ignore_errors=False, onerror=errorRemoveReadonly) # pylint: disable=deprecated-argument
shutil.rmtree(found.path, ignore_errors=False, onexc=excRemoveReadonly)
# extensions.extensions = [extension for extension in extensions.extensions if os.path.abspath(found.path) != os.path.abspath(extension_path)]
except Exception as e:
shared.log.warning(f'Extension uninstall failed: {found.path} {e}')