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)
This commit is contained in:
Kovid Goyal 2013-10-17 12:34:35 +05:30
parent 09775678bb
commit 6b575eba33
2 changed files with 16 additions and 1 deletions

View File

@ -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:

View File

@ -5,6 +5,7 @@ __license__ = 'GPL v3'
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
__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,