CGCookie / blender-addon-updater

A module for enabling users to check for add-on updates and install new versions directly from Blender.
GNU General Public License v3.0
247 stars 42 forks source link

Handle missing file access permissions more gracefully? #78

Open Dragorn421 opened 3 years ago

Dragorn421 commented 3 years ago

When an addon is mistakenly installed under a Blender installation folder which happens to be under C:\Program Files\, the updater addon will eventually raise an error during registering due to not having write access to the filesystem there

I'm using an old version of the updater addon but looking at current code this is probably still relevant. Sorry if it got addressed and I should just bother updating, lazy me

Here's the trace

io_export_objex2 updater verbose is enabled
Exception in module register(): C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\__init__.py
Traceback (most recent call last):
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\modules\addon_utils.py", line 382, in enable
    mod.register()
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\__init__.py", line 564, in register
    addon_updater_ops.register(bl_info)
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\addon_updater_ops.py", line 1509, in register
    showReloadPopup()
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\addon_updater_ops.py", line 835, in showReloadPopup
    saved_state = updater.json
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\addon_updater.py", line 298, in json
    self.set_updater_json()
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\scripts\addons\io_export_objex2\addon_updater.py", line 1467, in set_updater_json
    os.makedirs(self._updater_path)
  File "C:\Program Files\Blender Foundation\Blender 2.91\2.91\python\lib\os.py", line 223, in makedirs
    mkdir(name, mode)
PermissionError: [WinError 5] Access is denied: 'C:\\Program Files\\Blender Foundation\\Blender 2.91\\2.91\\scripts\\addons\\io_export_objex2\\io_export_objex2_updater'

Since this halts the registering, the addon doesn't unregister either and further registering attempts (eg by the user clicking the "enable addon" checkbox again) raise misleading errors about already-registered classes.

I think it would be nice to have the autoupdater handle "no file write permission" more gracefully. Maybe it should just disable itself and draw a message about "installed in the wrong directory, don't have write permissions" in the addon properties where the updater properties would be?

I can take care of PRing the necessary changes, I just want to find what the best way to handle this is first

TheDuckCow commented 3 years ago

Thanks a ton for sharing this issue edge case! We for sure don't want to break registration, appreciate all the details here - and a thousand times more if you're willing to do the PR! I'd be happy to review and give guidance if unsure where to start, but you should be able to make use of the error and error_msg fields for some of this, and also detecting if this is set within the draw window before drawing anything else.

I think it would be good to make sure there are stdout printouts, as well as a default label drawn in preferences in place of the rest of the UI indicating as you say, "Updater has no write permissions." with maybe some subtext for: "Try running blender as admin." Not sure if there's a nicely succinct way of describing "If you installed into the blender core addons folder, try installing to the user folder", as that could be wordy and just cause more confusion.

The other thing we should likely try to do in that state is still offer the "manual download" option, which is a button that just opens the according releases page, so it's still at least somewhat useful.