Skip to content

Windows: fail if not recyclable#89

Open
Dobatymo wants to merge 4 commits intoarsenetar:masterfrom
Dobatymo:safe-delete
Open

Windows: fail if not recyclable#89
Dobatymo wants to merge 4 commits intoarsenetar:masterfrom
Dobatymo:safe-delete

Conversation

@Dobatymo
Copy link
Copy Markdown

@Dobatymo Dobatymo commented Mar 13, 2024

Should fix #28

  • Deletion can only be aborted by raising an exception. The reason for this is that pywin32 doesn't use the result of the callback functions as HR value. However since FOFX_EARLYFAILURE is used anyway, aborting using an exception should be fine. A unavoidable (?) log will be printed though.
pythoncom error: Unexpected exception in gateway method 'PreDeleteItem'

Traceback (most recent call last):
  File "...\Python38\lib\site-packages\win32com\server\policy.py", line 355, in _InvokeEx_
    return self._invokeex_(dispid, lcid, wFlags, args, kwargs, serviceProvider)
  File "...\Python38\lib\site-packages\win32com\server\policy.py", line 637, in _invokeex_
    return func(*args)
  File "...\send2trash\win\IFileOperationProgressSink.py", line 47, in PreDeleteItem
    raise E_Fail(f"File would be deleted permanently: {name}")
send2trash.win.IFileOperationProgressSink.E_Fail: File would be deleted permanently: ...\send2trash\tmp\0

later the operation will raise an "unknown error" in this case (which can be caught)

Traceback (most recent call last):
  File "...\send2trash\win\modern.py", line 65, in send2trash
    result = fileop.PerformOperations()
pywintypes.com_error: (-2147467259, 'unknown error', None, None)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "prog.py", line 19, in <module>
    send2trash(paths)
  File "...\send2trash\win\modern.py", line 77, in send2trash
    raise win_exception(hr, path)
OSError: [WinError -2147467259] unknown error: ...\\send2trash\\tmp\\0'
  • Error handling was slightly improved. Previously the exception would always contain the filename of the last item in the list, not the file for which the call actually failed. Also some unusual errors (at the moment only COPYENGINE_E_SHARING_VIOLATION_SRC) are converted to standard exceptions (in this case a PermissionError)

I tested on Windows 7 and Windows 11.

@Dobatymo Dobatymo marked this pull request as draft March 13, 2024 12:31
@Dobatymo Dobatymo changed the title Wndows: fail if not recyclable Windows: fail if not recyclable Mar 13, 2024
@Dobatymo Dobatymo marked this pull request as ready for review May 14, 2024 07:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Windows backend can really delete files in some conditions

1 participant