From 92209fb6b8c35fc71ff4d0796a48eaaed2857690 Mon Sep 17 00:00:00 2001 From: Richard Kimberly Heck Date: Wed, 20 Dec 2023 20:19:12 -0500 Subject: [PATCH] Attempt to fix bug #13017. We should not remove the aux and bbl files when the Buffer is actively being exported. --- src/Buffer.cpp | 6 ++++++ src/Buffer.h | 8 +++++--- src/frontends/Application.h | 2 ++ src/frontends/qt/GuiApplication.cpp | 12 ++++++++++++ src/frontends/qt/GuiApplication.h | 1 + src/frontends/qt/GuiView.cpp | 9 +++++++++ src/frontends/qt/GuiView.h | 2 ++ 7 files changed, 37 insertions(+), 3 deletions(-) diff --git a/src/Buffer.cpp b/src/Buffer.cpp index 732ca7e323..7522dce434 100644 --- a/src/Buffer.cpp +++ b/src/Buffer.cpp @@ -2689,6 +2689,11 @@ bool Buffer::citeLabelsValid() const void Buffer::removeBiblioTempFiles() const { + if (theApp()->isBufferBusy(this)) { + removeBiblioTemps = true; + return; + } + // We remove files that contain LaTeX commands specific to the // particular bibliographic style being used, in order to avoid // LaTeX errors when we switch style. @@ -2702,6 +2707,7 @@ void Buffer::removeBiblioTempFiles() const Buffer const * const pbuf = parent(); if (pbuf) pbuf->removeBiblioTempFiles(); + removeBiblioTemps = false; } diff --git a/src/Buffer.h b/src/Buffer.h index de27084af9..0ebd2f64eb 100644 --- a/src/Buffer.h +++ b/src/Buffer.h @@ -806,18 +806,20 @@ public: /// of loaded child documents). docstring_list const & getBibfiles(UpdateScope scope = UpdateMaster) const; - + /// + bool needToRemoveBiblioTemps() const { return removeBiblioTemps; } /// routines for dealing with possible self-inclusion void pushIncludedBuffer(Buffer const * buf) const; void popIncludedBuffer() const; bool isBufferIncluded(Buffer const * buf) const; private: void clearIncludeList() const; - -private: + /// friend class MarkAsExporting; /// mark the buffer as busy exporting something, or not void setExportStatus(bool e) const; + /// + mutable bool removeBiblioTemps = false; /// References & getReferenceCache(docstring const & label); diff --git a/src/frontends/Application.h b/src/frontends/Application.h index 75298ca67a..429b322baf 100644 --- a/src/frontends/Application.h +++ b/src/frontends/Application.h @@ -255,6 +255,8 @@ public: virtual bool unhide(Buffer * buf) = 0; // Apply preferences at the start static void applyPrefs(); + /// + virtual bool isBufferBusy(Buffer const * b) = 0; }; /// Return the list of loadable formats. diff --git a/src/frontends/qt/GuiApplication.cpp b/src/frontends/qt/GuiApplication.cpp index 26288a5f55..9e3cd70392 100644 --- a/src/frontends/qt/GuiApplication.cpp +++ b/src/frontends/qt/GuiApplication.cpp @@ -1258,6 +1258,18 @@ void GuiApplication::clearSession() } +bool GuiApplication::isBufferBusy(Buffer const * b) +{ + Buffer const * buf = b; + while (buf) { + if (GuiView::isBufferBusy(b)) + return true; + buf = buf->parent(); + } + return false; +} + + docstring Application::iconName(FuncRequest const & f, bool unknown) { return qstring_to_ucs4(lyx::frontend::iconInfo(f, unknown, false).filepath); diff --git a/src/frontends/qt/GuiApplication.h b/src/frontends/qt/GuiApplication.h index b27964dde4..8adaa701c1 100644 --- a/src/frontends/qt/GuiApplication.h +++ b/src/frontends/qt/GuiApplication.h @@ -83,6 +83,7 @@ public: std::string inputLanguageCode() const override; void handleKeyFunc(FuncCode action) override; bool unhide(Buffer * buf) override; + bool isBufferBusy(Buffer const * b) override; //@} /// diff --git a/src/frontends/qt/GuiView.cpp b/src/frontends/qt/GuiView.cpp index 79ffc0a207..5a5c1dac8d 100644 --- a/src/frontends/qt/GuiView.cpp +++ b/src/frontends/qt/GuiView.cpp @@ -527,6 +527,7 @@ public: string last_export_format; string processing_format; + // Buffers that are being exported static QSet busyBuffers; unsigned int smallIconSize; @@ -3451,6 +3452,12 @@ bool GuiView::exportBufferAs(Buffer & b, docstring const & iformat) } +bool GuiView::isBufferBusy(Buffer const * b) +{ + return GuiViewPrivate::busyBuffers.contains(b); +} + + bool GuiView::saveBuffer(Buffer & b) { return saveBuffer(b, FileName()); @@ -4227,6 +4234,8 @@ Buffer::ExportStatus GuiView::GuiViewPrivate::runAndDestroy(const T& func, // documents, starting from the master. so we must delete those. Buffer * mbuf = const_cast(clone->masterBuffer()); delete mbuf; + if (orig->needToRemoveBiblioTemps()) + orig->removeBiblioTempFiles(); busyBuffers.remove(orig); return status; } diff --git a/src/frontends/qt/GuiView.h b/src/frontends/qt/GuiView.h index d55472d267..42bc1878c5 100644 --- a/src/frontends/qt/GuiView.h +++ b/src/frontends/qt/GuiView.h @@ -220,6 +220,8 @@ public: /// Current ratio between physical pixels and device-independent pixels double pixelRatio() const; + /// + static bool isBufferBusy(Buffer const * b); Q_SIGNALS: void closing(int); -- 2.39.2