mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-09 03:04:10 -04:00
Also warn about read-only files just before saving
This commit is contained in:
parent
d185190c61
commit
5c30cc142a
@ -107,6 +107,7 @@ class Boss(QObject):
|
|||||||
def __init__(self, parent, notify=None):
|
def __init__(self, parent, notify=None):
|
||||||
QObject.__init__(self, parent)
|
QObject.__init__(self, parent)
|
||||||
self.global_undo = GlobalUndoHistory()
|
self.global_undo = GlobalUndoHistory()
|
||||||
|
self.file_was_readonly = False
|
||||||
self.container_count = 0
|
self.container_count = 0
|
||||||
self.tdir = None
|
self.tdir = None
|
||||||
self.save_manager = SaveManager(parent, notify)
|
self.save_manager = SaveManager(parent, notify)
|
||||||
@ -318,9 +319,6 @@ class Boss(QObject):
|
|||||||
if not os.path.exists(path):
|
if not os.path.exists(path):
|
||||||
return error_dialog(self.gui, _('File not found'), _(
|
return error_dialog(self.gui, _('File not found'), _(
|
||||||
'The file %s does not exist.') % path, show=True)
|
'The file %s does not exist.') % path, show=True)
|
||||||
if not os.access(path, os.W_OK):
|
|
||||||
warning_dialog(self.gui, _('Read-only file'), _(
|
|
||||||
'The file {} is read-only. Saving changes to it will either fail or cause its permissions to be reset.').format(path), show=True)
|
|
||||||
isdir = os.path.isdir(path)
|
isdir = os.path.isdir(path)
|
||||||
ext = path.rpartition('.')[-1].upper()
|
ext = path.rpartition('.')[-1].upper()
|
||||||
if ext not in SUPPORTED and not isdir:
|
if ext not in SUPPORTED and not isdir:
|
||||||
@ -332,6 +330,11 @@ class Boss(QObject):
|
|||||||
' Convert your book to one of these formats first.') % _(' and ').join(sorted(SUPPORTED)),
|
' Convert your book to one of these formats first.') % _(' and ').join(sorted(SUPPORTED)),
|
||||||
show=True)
|
show=True)
|
||||||
|
|
||||||
|
self.file_was_readonly = not os.access(path, os.W_OK)
|
||||||
|
if self.file_was_readonly:
|
||||||
|
warning_dialog(self.gui, _('Read-only file'), _(
|
||||||
|
'The file {} is read-only. Saving changes to it will either fail or cause its permissions to be reset.').format(path), show=True)
|
||||||
|
|
||||||
for name in tuple(editors):
|
for name in tuple(editors):
|
||||||
self.close_editor(name)
|
self.close_editor(name)
|
||||||
self.gui.preview.clear()
|
self.gui.preview.clear()
|
||||||
@ -1302,6 +1305,11 @@ class Boss(QObject):
|
|||||||
self.global_undo.update_path_to_ebook(path)
|
self.global_undo.update_path_to_ebook(path)
|
||||||
else:
|
else:
|
||||||
return
|
return
|
||||||
|
if os.path.exists(c.path_to_ebook) and not os.access(c.path_to_ebook, os.W_OK):
|
||||||
|
if not question_dialog(self.gui, _('File is read-only'), _(
|
||||||
|
'The file at {} is read-only. The editor will try to reset its permissions before saving. Proceed with saving?'
|
||||||
|
).format(c.path_to_ebook), override_icon='dialog_warning.png', yes_text=_('&Save'), no_text=_('&Cancel'), yes_icon='save.png'):
|
||||||
|
return
|
||||||
self.gui.action_save.setEnabled(False)
|
self.gui.action_save.setEnabled(False)
|
||||||
tdir = self.mkdtemp(prefix='save-')
|
tdir = self.mkdtemp(prefix='save-')
|
||||||
container = clone_container(c, tdir)
|
container = clone_container(c, tdir)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user