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>
This commit is contained in:
parent
1dbbc5acc7
commit
1845ed42af
3 changed files with 20 additions and 3 deletions
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
|
||||
|
|
Loading…
Reference in a new issue