mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
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:
parent
09775678bb
commit
6b575eba33
@ -1397,6 +1397,10 @@ class Cache(object):
|
|||||||
except:
|
except:
|
||||||
path = None
|
path = None
|
||||||
path_map[book_id] = path
|
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)
|
self.backend.remove_books(path_map, permanent=permanent)
|
||||||
for field in self.fields.itervalues():
|
for field in self.fields.itervalues():
|
||||||
try:
|
try:
|
||||||
|
@ -5,6 +5,7 @@ __license__ = 'GPL v3'
|
|||||||
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
__copyright__ = '2010, Kovid Goyal <kovid@kovidgoyal.net>'
|
||||||
__docformat__ = 'restructuredtext en'
|
__docformat__ = 'restructuredtext en'
|
||||||
|
|
||||||
|
import errno
|
||||||
from functools import partial
|
from functools import partial
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
|
|
||||||
@ -360,7 +361,17 @@ class DeleteAction(InterfaceAction):
|
|||||||
return
|
return
|
||||||
next_id = view.next_id
|
next_id = view.next_id
|
||||||
if len(to_delete_ids) < 5:
|
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)
|
self.library_ids_deleted2(to_delete_ids, next_id=next_id)
|
||||||
else:
|
else:
|
||||||
self.__md = MultiDeleter(self.gui, to_delete_ids,
|
self.__md = MultiDeleter(self.gui, to_delete_ids,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user