[Libreoffice-commits] online.git: wsd/DocumentBroker.cpp wsd/DocumentBroker.hpp wsd/LOOLWSD.cpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue May 21 23:58:10 UTC 2019


 wsd/DocumentBroker.cpp |   11 ++++++++---
 wsd/DocumentBroker.hpp |    3 +++
 wsd/LOOLWSD.cpp        |    9 +++++++++
 3 files changed, 20 insertions(+), 3 deletions(-)

New commits:
commit 1845ed42af661dbb7b10a2fb4686ce2c8ef7e521
Author:     Michael Meeks <michael.meeks at collabora.com>
AuthorDate: Tue May 21 19:50:17 2019 +0100
Commit:     Michael Meeks <michael.meeks at collabora.com>
CommitDate: Wed May 22 01:57:48 2019 +0200

    tdf#123482 - cleanup convert-to folder even more reliably.
    
    Problems could occur if exceptiosn thrown when parsing the input stream.
    
    Change-Id: Id82b3816450194164fc2093554c730b4a94acef1
    Reviewed-on: https://gerrit.libreoffice.org/72695
    Reviewed-by: Michael Meeks <michael.meeks at collabora.com>
    Tested-by: Michael Meeks <michael.meeks at collabora.com>

diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp
index 6779473a4..698f3dd98 100644
--- a/wsd/DocumentBroker.cpp
+++ b/wsd/DocumentBroker.cpp
@@ -1908,13 +1908,18 @@ ConvertToBroker::ConvertToBroker(const std::string& uri,
 ConvertToBroker::~ConvertToBroker()
 {
     NumConverters--;
-    if (!_uriOrig.empty())
+    removeFile(_uriOrig);
+}
+
+void ConvertToBroker::removeFile(const std::string &uriOrig)
+{
+    if (!uriOrig.empty())
     {
         // Remove source file and directory
-        Poco::Path path = _uriOrig;
+        Poco::Path path = uriOrig;
         Poco::File(path).remove();
         Poco::File(path.makeParent()).remove();
-        FileUtil::removeFile(_uriOrig);
+        FileUtil::removeFile(uriOrig);
     }
 }
 
diff --git a/wsd/DocumentBroker.hpp b/wsd/DocumentBroker.hpp
index 0642599c2..c56ced733 100644
--- a/wsd/DocumentBroker.hpp
+++ b/wsd/DocumentBroker.hpp
@@ -481,6 +481,9 @@ public:
 
     /// How many live conversions are running.
     static size_t getInstanceCount();
+
+    /// Cleanup path and its parent
+    static void removeFile(const std::string &uri);
 };
 
 #endif
diff --git a/wsd/LOOLWSD.cpp b/wsd/LOOLWSD.cpp
index 69e74114a..25877811a 100644
--- a/wsd/LOOLWSD.cpp
+++ b/wsd/LOOLWSD.cpp
@@ -572,6 +572,9 @@ class ConvertToPartHandler : public PartHandler
 public:
     std::string getFilename() const { return _filename; }
 
+    /// Afterwards someone else is responsible for cleaning that up.
+    void takeFile() { _filename.clear(); }
+
     ConvertToPartHandler(bool convertTo = false)
         : _convertTo(convertTo)
     {
@@ -579,6 +582,11 @@ public:
 
     virtual ~ConvertToPartHandler()
     {
+        if (!_filename.empty())
+        {
+            LOG_TRC("Remove un-handled temporary file '" << _filename << "'");
+            ConvertToBroker::removeFile(_filename);
+        }
     }
 
     virtual void handlePart(const MessageHeader& header, std::istream& stream) override
@@ -2377,6 +2385,7 @@ private:
 
                     LOG_DBG("New DocumentBroker for docKey [" << docKey << "].");
                     auto docBroker = std::make_shared<ConvertToBroker>(fromPath, uriPublic, docKey);
+                    handler.takeFile();
 
                     cleanupDocBrokers();
 


More information about the Libreoffice-commits mailing list