From 64c4f1974b19acf18ad8b3017acd071dfca62de5 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Wed, 3 Jul 2013 03:52:16 +0900 Subject: [PATCH] fall back on regular delete on broken recycle bin (#926) --- thirdparty/send2trash/plat_osx.py | 8 ++++++++ thirdparty/send2trash/plat_other.py | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/thirdparty/send2trash/plat_osx.py b/thirdparty/send2trash/plat_osx.py index 0855efdb5..4feaac95c 100644 --- a/thirdparty/send2trash/plat_osx.py +++ b/thirdparty/send2trash/plat_osx.py @@ -6,6 +6,7 @@ from ctypes import cdll, byref, Structure, c_char, c_char_p from ctypes.util import find_library +import os Foundation = cdll.LoadLibrary(find_library(u'Foundation')) CoreServices = cdll.LoadLibrary(find_library(u'CoreServices')) @@ -33,6 +34,13 @@ def check_op_result(op_result): raise OSError(msg) def send2trash(path): + try: + _send2trash(path) + except OSError: + # user's system is broken; just delete + os.unlink(path) + +def _send2trash(path): if not isinstance(path, str): path = path.encode(u'utf-8') fp = FSRef() diff --git a/thirdparty/send2trash/plat_other.py b/thirdparty/send2trash/plat_other.py index abd348efd..aa44bf335 100644 --- a/thirdparty/send2trash/plat_other.py +++ b/thirdparty/send2trash/plat_other.py @@ -129,6 +129,13 @@ def get_dev(path): return os.lstat(path).st_dev def send2trash(path): + try: + _send2trash(path) + except OSError: + # user's system is broken; just delete + os.unlink(path) + +def _send2trash(path): if not isinstance(path, unicode): path = unicode(path, sys.getfilesystemencoding()) if not op.exists(path): @@ -155,3 +162,4 @@ def send2trash(path): raise OSError(u"Couldn't find mount point for %s" % path) dest_trash = find_ext_volume_trash(topdir) trash_move(path, dest_trash, topdir) +