]> git.lyx.org Git - features.git/commitdiff
Do not overwrite read-only files. We now move the file to the backup directory and...
authorVincent van Ravesteijn <vfr@lyx.org>
Fri, 26 Nov 2010 04:17:20 +0000 (04:17 +0000)
committerVincent van Ravesteijn <vfr@lyx.org>
Fri, 26 Nov 2010 04:17:20 +0000 (04:17 +0000)
git-svn-id: svn://svn.lyx.org/lyx/lyx-devel/trunk@36499 a592a061-630c-0410-9148-cb99ea01b6c8

src/Buffer.cpp

index 9cb4b5d5e864654bc1c923f7efa08bd026b191a0..4e18634dd4f4972c93c39bd96056445868710483 100644 (file)
@@ -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)