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(fromPath, uriPublic, docKey); + handler.takeFile(); cleanupDocBrokers();