mirror of
https://github.com/arsenetar/send2trash.git
synced 2024-11-10 17:59:03 +00:00
fix assertion for missing files
This commit is contained in:
parent
5e9d56bdcb
commit
79caa04fea
@ -63,22 +63,27 @@ def send2trash(paths):
|
|||||||
# 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:
|
||||||
for path in paths:
|
try:
|
||||||
item = shell.SHCreateItemFromParsingName(path, None, shell.IID_IShellItem)
|
for path in paths:
|
||||||
fileop.DeleteItem(item, sink)
|
item = shell.SHCreateItemFromParsingName(path, None, shell.IID_IShellItem)
|
||||||
result = fileop.PerformOperations()
|
fileop.DeleteItem(item, sink)
|
||||||
aborted = fileop.GetAnyOperationsAborted()
|
except pywintypes.com_error as error:
|
||||||
# if non-zero result or aborted throw an exception
|
# convert to standard OS error, allows other code to get a
|
||||||
assert not pysink.errors, pysink.errors
|
# normal errno
|
||||||
if result or aborted:
|
raise OSError(None, error.strerror, path, error.hresult)
|
||||||
raise OSError(None, None, paths, result)
|
|
||||||
except pywintypes.com_error:
|
try:
|
||||||
assert len(pysink.errors) == 1, pysink.errors
|
result = fileop.PerformOperations()
|
||||||
# convert to standard OS error, allows other code to get a
|
aborted = fileop.GetAnyOperationsAborted()
|
||||||
# normal errno
|
# if non-zero result or aborted throw an exception
|
||||||
path, hr = pysink.errors[0]
|
assert not pysink.errors, pysink.errors
|
||||||
hr = winerrormap.get(hr + 2**32, hr)
|
if result or aborted:
|
||||||
raise win_exception(hr, path)
|
raise OSError(None, None, paths, result)
|
||||||
|
except pywintypes.com_error:
|
||||||
|
assert len(pysink.errors) == 1, pysink.errors
|
||||||
|
path, hr = pysink.errors[0]
|
||||||
|
hr = winerrormap.get(hr + 2**32, hr)
|
||||||
|
raise win_exception(hr, path)
|
||||||
finally:
|
finally:
|
||||||
# Need to make sure we call this once fore every init
|
# Need to make sure we call this once fore every init
|
||||||
pythoncom.CoUninitialize()
|
pythoncom.CoUninitialize()
|
||||||
|
Loading…
Reference in New Issue
Block a user