commit 2a771febd1ac49dbcef94d3f4b31a023ad19bc2e
Author: Pavel Sanda <sa...@lyx.org>
Date:   Sat Feb 8 11:54:16 2025 +0100

    Another attempt on #12819 - check for deleted documents.
    
    ATM we detected some file rewrites as removal and we need
    time delay to handle this.
    More detailed comments at #12819.
    
    https://www.mail-archive.com/lyx-devel@lists.lyx.org/msg223557.html
---
 src/Buffer.cpp | 28 ++++++++++++++++++++--------
 1 file changed, 20 insertions(+), 8 deletions(-)

diff --git a/src/Buffer.cpp b/src/Buffer.cpp
index f9ad2dcd6b..3d05442398 100644
--- a/src/Buffer.cpp
+++ b/src/Buffer.cpp
@@ -5681,14 +5681,26 @@ void Buffer::Impl::fileExternallyModified(bool const 
exists)
        // Dirty buffers must be visible at all times.
        if (wa_ && wa_->unhide(owner_)) {
                wa_->updateTitles();
-               if (!exists) {
-                       lyx_clean = false;
-                       frontend::Alert::warning(
-                               _("File deleted from disk"),
-                               bformat(_("The file\n  %1$s\n"
-                                          "has been deleted from disk!"),
-                                       from_utf8(filename.absFileName())));
-               }
+
+               if (exists)
+                       return;
+               //Essentially the same problem as in FileMonitorGuard::refresh.
+               //'exists' is not reliable marker of file removal here, e.g.
+               //file overwrite often causes short-term removal, see #12819.
+               std::this_thread::sleep_for(100ms);
+               FileName refreshf (filename.absFileName());
+               //Only double check with delay will trigger warning
+               if(refreshf.exists())
+                       return;
+
+               lyx_clean = false;
+               wa_->updateTitles();
+               frontend::Alert::warning(
+                       _("File deleted from disk"),
+                       bformat(_("The file\n  %1$s\n"
+                                  "has been deleted from disk!\n"
+                                  "It will be marked as modified now."),
+                               from_utf8(filename.absFileName())));
        }
        else
                // Unable to unhide the buffer (e.g. no GUI or not current View)
-- 
lyx-cvs mailing list
lyx-cvs@lists.lyx.org
https://lists.lyx.org/mailman/listinfo/lyx-cvs

Reply via email to