Open lukaszgo1 opened 3 years ago
cc: @seanbudd
Given this is blocked by a python upgrade I am adding this to the 2024.1 milestone
Now that we are on Python 3.11 we plan to take this on, unless you plan to @lukaszgo1
@seanbudd From my initial comment, this is (or was) blocked by the Python 3.11 upgrade if and only if, we prefer to use SHFileOperationW
, which is legacy, and no longer recommended by Microsoft for applications which do not need to target Windows XP. I can work on this and try to use IFileOperation
which is the more modern replacement, though I haven't worked with COM that much, so it might take a while. On the other hand I don't think there is a particular rush, as this issue is encountered pretty rarely.
Discovered when working on #12792
Steps to reproduce:
Actual behavior:
NVDA fails to finish uninstallation and asks user to remove the folder manually.
Expected behavior:
Plugin should uninstall normally since even though it contains read-only files Windows Explorer can remove its folder successfully.
System configuration
NVDA installed/portable/running from source:
Tested from sources but probably not relevant
NVDA version:
Latest master as of September 9th.
Windows version:
N/A
Name and version of other software in use when reproducing the issue:
None
Other information about your system:
None relevant
Other questions
Does the issue still occur after restarting your computer?
Yes
Have you tried any other versions of NVDA? If so, please report their behaviors.
No, but this behavior is not new
If add-ons are disabled, is your problem still occurring?
No but this is about NVDA's interaction with add-ons
Does the issue still occur after you run the COM Registration Fixing Tool in NVDA's tools menu?
Not tried since it is not relevant.
Technical:
The problem occurs because we're using
shutil.rmtree
to remove the add-on directory and this function is incapable of removing read-only files. The only solution is to use different way of removing the folder. My first thought was to useSHFileOperationW
we even have necessary structures defined inshellapi
. Unfortunately while this solution works from the standard Python interpreter it cannot be used from NVDA currently. After a lot of research it turns out that Python 3.5 up to 3.7 which we're using has a bug which prevents usages of null terminated strings in ctypes structures andSHFileOperationW
uses null as a path separator. I see the following ways of dealing with this problem:SHFileOperationW
- the bug linked above is fixed in 3.8 and up though given the current problems with moving to more recent version of Python this may take a while.SHFileOperationW
in NVDAHelper and use it to remove the directory - we have some utility functions in NVDAHelper so there is a precedent for this.IFileOperation
which is a more moder replacement forSHFileOperationW
though it seems to be much harder to use in general and accessing it from Python makes it even harder. On the flip side it does not require nulls as path separator.