From 70735023086bc5eb88126d4af07a9a505adfae27 Mon Sep 17 00:00:00 2001 From: Vincent van Ravesteijn Date: Fri, 26 Nov 2010 04:17:20 +0000 Subject: [PATCH] Do not overwrite read-only files. We now move the file to the backup directory and write a new file. However, when the file is read-only it now appears as the file is overwritten anyway. Therefore we check wether the file is read-only before moving it. git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36499 a592a061-630c-0410-9148-cb99ea01b6c8 --- src/Buffer.cpp | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 9cb4b5d5e8..4e18634dd4 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -1008,11 +1008,25 @@ Buffer::ReadStatus Buffer::convertLyXFormat(FileName const & fn, // Should probably be moved to somewhere else: BufferView? GuiView? bool Buffer::save() const { + docstring const file = makeDisplayPath(absFileName(), 20); + d->filename.refresh(); + + // check the read-only status before moving the file as a backup + if (d->filename.exists()) { + bool const read_only = !d->filename.isWritable(); + if (read_only) { + Alert::warning(_("File is read-only"), + bformat(_("The file %1$s cannot be written because it " + "is marked as read-only."), file)); + return false; + } + } + // ask if the disk file has been externally modified (use checksum method) if (fileName().exists() && isExternallyModified(checksum_method)) { - docstring const file = makeDisplayPath(absFileName(), 20); - docstring text = bformat(_("Document %1$s has been externally modified. Are you sure " - "you want to overwrite this file?"), file); + docstring text = + bformat(_("Document %1$s has been externally modified. " + "Are you sure you want to overwrite this file?"), file); int const ret = Alert::prompt(_("Overwrite modified file?"), text, 1, 1, _("&Overwrite"), _("&Cancel")); if (ret == 1)