diff --git a/src/calibre/db/tests/base.py b/src/calibre/db/tests/base.py index 7a44897600..e541b410f2 100644 --- a/src/calibre/db/tests/base.py +++ b/src/calibre/db/tests/base.py @@ -27,10 +27,14 @@ class BaseTest(unittest.TestCase): reset_tweaks_to_default() def setUp(self): + from calibre.utils.recycle_bin import nuke_recycle + nuke_recycle() self.library_path = self.mkdtemp() self.create_db(self.library_path) def tearDown(self): + from calibre.utils.recycle_bin import restore_recyle + restore_recyle() gc.collect(), gc.collect() shutil.rmtree(self.library_path) diff --git a/src/calibre/utils/recycle_bin.py b/src/calibre/utils/recycle_bin.py index d1a63e8d01..7b1b38261b 100644 --- a/src/calibre/utils/recycle_bin.py +++ b/src/calibre/utils/recycle_bin.py @@ -36,8 +36,16 @@ elif islinux: can_recycle = callable(recycle) -def delete_file(path): - if callable(recycle): +def nuke_recycle(): + global can_recycle + can_recycle = False + +def restore_recyle(): + global can_recycle + can_recycle = callable(recycle) + +def delete_file(path, permanent=False): + if not permanent and can_recycle: try: recycle(path) return @@ -59,7 +67,7 @@ def delete_tree(path, permanent=False): time.sleep(1) shutil.rmtree(path) else: - if callable(recycle): + if can_recycle: try: recycle(path) return