diff --git a/src/calibre/gui2/tweak_book/boss.py b/src/calibre/gui2/tweak_book/boss.py index b9dcacb193..23ce37a42d 100644 --- a/src/calibre/gui2/tweak_book/boss.py +++ b/src/calibre/gui2/tweak_book/boss.py @@ -107,6 +107,7 @@ class Boss(QObject): def __init__(self, parent, notify=None): QObject.__init__(self, parent) self.global_undo = GlobalUndoHistory() + self.file_was_readonly = False self.container_count = 0 self.tdir = None self.save_manager = SaveManager(parent, notify) @@ -318,9 +319,6 @@ class Boss(QObject): if not os.path.exists(path): return error_dialog(self.gui, _('File not found'), _( '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) ext = path.rpartition('.')[-1].upper() 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)), 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): self.close_editor(name) self.gui.preview.clear() @@ -1302,6 +1305,11 @@ class Boss(QObject): self.global_undo.update_path_to_ebook(path) else: 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) tdir = self.mkdtemp(prefix='save-') container = clone_container(c, tdir)