diff options
author | Michael Meeks <michael.meeks@collabora.com> | 2019-05-21 19:50:17 +0100 |
---|---|---|
committer | Samuel Mehrbrodt <Samuel.Mehrbrodt@cib.de> | 2020-04-14 08:25:11 +0200 |
commit | c6e72be9fcdf3a3439266f4e3b7a4f87565f2c3c (patch) | |
tree | bba83899533dc8db57d21d05b11b66f426aee9e5 | |
parent | dab5603fc6bdb9ffbc576c9ae693724484f31b37 (diff) |
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@collabora.com>
Tested-by: Michael Meeks <michael.meeks@collabora.com>
(cherry picked from commit 1845ed42af661dbb7b10a2fb4686ce2c8ef7e521)
-rw-r--r-- | wsd/DocumentBroker.cpp | 11 | ||||
-rw-r--r-- | wsd/DocumentBroker.hpp | 3 | ||||
-rw-r--r-- | wsd/LOOLWSD.cpp | 9 |
3 files changed, 20 insertions, 3 deletions
diff --git a/wsd/DocumentBroker.cpp b/wsd/DocumentBroker.cpp index 86524325f..61691133f 100644 --- a/wsd/DocumentBroker.cpp +++ b/wsd/DocumentBroker.cpp @@ -1880,13 +1880,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 4e628af12..b2c7543ba 100644 --- a/wsd/DocumentBroker.hpp +++ b/wsd/DocumentBroker.hpp @@ -484,6 +484,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 4878e116e..5415224fa 100644 --- a/wsd/LOOLWSD.cpp +++ b/wsd/LOOLWSD.cpp @@ -570,6 +570,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) { @@ -577,6 +580,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 @@ -2362,6 +2370,7 @@ private: LOG_DBG("New DocumentBroker for docKey [" << docKey << "]."); auto docBroker = std::make_shared<ConvertToBroker>(fromPath, uriPublic, docKey); + handler.takeFile(); cleanupDocBrokers(); |