From 6b575eba33499ef175ae5239567d323dfd03553d Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Thu, 17 Oct 2013 12:34:35 +0530 Subject: [PATCH] Windows: Check if the books' files are in use before deleting Fixes #1240788 [Calibre refused to delete book](https://bugs.launchpad.net/calibre/+bug/1240788) --- src/calibre/db/cache.py | 4 ++++ src/calibre/gui2/actions/delete.py | 13 ++++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/calibre/db/cache.py b/src/calibre/db/cache.py index 80361393c5..6a4ed4708e 100644 --- a/src/calibre/db/cache.py +++ b/src/calibre/db/cache.py @@ -1397,6 +1397,10 @@ class Cache(object): except: path = None path_map[book_id] = path + if iswindows: + paths = (x.replace(os.sep, '/') for x in path_map.itervalues() if x) + self.backend.windows_check_if_files_in_use(paths) + self.backend.remove_books(path_map, permanent=permanent) for field in self.fields.itervalues(): try: diff --git a/src/calibre/gui2/actions/delete.py b/src/calibre/gui2/actions/delete.py index ab5e52d69c..ddd71ee18f 100644 --- a/src/calibre/gui2/actions/delete.py +++ b/src/calibre/gui2/actions/delete.py @@ -5,6 +5,7 @@ __license__ = 'GPL v3' __copyright__ = '2010, Kovid Goyal ' __docformat__ = 'restructuredtext en' +import errno from functools import partial from collections import Counter @@ -360,7 +361,17 @@ class DeleteAction(InterfaceAction): return next_id = view.next_id if len(to_delete_ids) < 5: - view.model().delete_books_by_id(to_delete_ids) + try: + view.model().delete_books_by_id(to_delete_ids) + except IOError as err: + if err.errno == errno.EACCES: + import traceback + fname = getattr(err, 'filename', 'file') or 'file' + return error_dialog(self.gui, _('Permission denied'), + _('Could not access %s. Is it being used by another' + ' program? Click "Show details" for more information.')%fname, det_msg=traceback.format_exc(), + show=True) + self.library_ids_deleted2(to_delete_ids, next_id=next_id) else: self.__md = MultiDeleter(self.gui, to_delete_ids,