1
0
mirror of https://github.com/arsenetar/send2trash.git synced 2024-11-13 02:59:02 +00:00

fix assertion for missing files

This commit is contained in:
Dobatymo 2024-03-13 20:35:19 +08:00
parent 5e9d56bdcb
commit 79caa04fea

View File

@ -62,10 +62,17 @@ def send2trash(paths):
# pywintypes.com_error which does not seem to create as nice of an # pywintypes.com_error which does not seem to create as nice of an
# error as OSError so wrapping with try to convert # error as OSError so wrapping with try to convert
pysink, sink = create_sink() pysink, sink = create_sink()
try:
try: try:
for path in paths: for path in paths:
item = shell.SHCreateItemFromParsingName(path, None, shell.IID_IShellItem) item = shell.SHCreateItemFromParsingName(path, None, shell.IID_IShellItem)
fileop.DeleteItem(item, sink) fileop.DeleteItem(item, sink)
except pywintypes.com_error as error:
# convert to standard OS error, allows other code to get a
# normal errno
raise OSError(None, error.strerror, path, error.hresult)
try:
result = fileop.PerformOperations() result = fileop.PerformOperations()
aborted = fileop.GetAnyOperationsAborted() aborted = fileop.GetAnyOperationsAborted()
# if non-zero result or aborted throw an exception # if non-zero result or aborted throw an exception
@ -74,8 +81,6 @@ def send2trash(paths):
raise OSError(None, None, paths, result) raise OSError(None, None, paths, result)
except pywintypes.com_error: except pywintypes.com_error:
assert len(pysink.errors) == 1, pysink.errors assert len(pysink.errors) == 1, pysink.errors
# convert to standard OS error, allows other code to get a
# normal errno
path, hr = pysink.errors[0] path, hr = pysink.errors[0]
hr = winerrormap.get(hr + 2**32, hr) hr = winerrormap.get(hr + 2**32, hr)
raise win_exception(hr, path) raise win_exception(hr, path)