From e17a51dbdab9545f79c77a91db26cb7b004386e6 Mon Sep 17 00:00:00 2001 From: Scurest Date: Tue, 30 Jan 2024 10:23:55 +0100 Subject: [PATCH] Addon: catch certain ZIP packaging errors in addon_install One error that occurs when packaging a multi-file addon into a ZIP is zipping the contents of the addon folder, instead of the addon folder itself. When installing the ZIP using addon_install, the files that should be inside a folder instead get extracted into the top-level of the script directory. There is also no user feedback about what went wrong. addon_install can detect this error by the presence of an __init__.py file at the top-level of the ZIP archive, and report an error. AFAIK there is no use-case for having an __init__.py in the top-level of the script directory, so there are no false positives. --- scripts/startup/bl_operators/userpref.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/scripts/startup/bl_operators/userpref.py b/scripts/startup/bl_operators/userpref.py index 1bfcd716ef2..35ad6fb11d2 100644 --- a/scripts/startup/bl_operators/userpref.py +++ b/scripts/startup/bl_operators/userpref.py @@ -674,6 +674,13 @@ class PREFERENCES_OT_addon_install(Operator): return {'CANCELLED'} file_to_extract_root = _zipfile_root_namelist(file_to_extract) + + if "__init__.py" in file_to_extract_root: + self.report({'ERROR'}, rpt_( + "ZIP packaged incorrectly; __init__.py should be in a folder, not at top-level" + )) + return {'CANCELLED'} + if self.overwrite: for f in file_to_extract_root: _module_filesystem_remove(path_addons, f) -- 2.30.2