diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-15 07:22:37 +0100 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2019-01-15 08:39:23 +0100 |
commit | a975d17e715bcf317e40d19ef47cc37660b81f7e (patch) | |
tree | 84a313b88d56a1054bc865684fc21ddd92afe918 /desktop/source | |
parent | 23a8d5ffbbe58761b89f590f0735abccd69a3681 (diff) |
Use utl::TempFile for exception safety
... to not leak temporary cat files
Change-Id: I99e230054f1a3ed6aabce63d427483808e969716
Reviewed-on: https://gerrit.libreoffice.org/66343
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'desktop/source')
-rw-r--r-- | desktop/source/app/dispatchwatcher.cxx | 41 |
1 files changed, 15 insertions, 26 deletions
diff --git a/desktop/source/app/dispatchwatcher.cxx b/desktop/source/app/dispatchwatcher.cxx index 21fa4ff6b956..3a8b2d9961a0 100644 --- a/desktop/source/app/dispatchwatcher.cxx +++ b/desktop/source/app/dispatchwatcher.cxx @@ -57,6 +57,7 @@ #include <comphelper/sequence.hxx> #include <tools/urlobj.hxx> #include <unotools/mediadescriptor.hxx> +#include <unotools/tempfile.hxx> #include <vector> #include <osl/thread.hxx> @@ -579,12 +580,15 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest FileBase::getFileURLFromSystemPath( aFilterOut, aFilterOut ); OUString aOutFile = aFilterOut + "/" + aOutFilename.getName(); - OUString fileForCat; + std::unique_ptr<utl::TempFile> fileForCat; if( aDispatchRequest.aRequestType == REQUEST_CAT ) { - if( ::osl::FileBase::createTempFile(nullptr, nullptr, &fileForCat) != ::osl::FileBase::E_None ) + fileForCat = std::make_unique<utl::TempFile>(); + if (fileForCat->IsValid()) + fileForCat->EnableKillingFile(); + else std::cerr << "Error: Cannot create temporary file..." << std::endl ; - aOutFile = fileForCat; + aOutFile = fileForCat->GetURL(); } if ( bGuess ) @@ -657,33 +661,18 @@ bool DispatchWatcher::executeDispatchRequests( const std::vector<DispatchRequest std::cerr << std::endl; } - if (aDispatchRequest.aRequestType == REQUEST_CAT) + if (fileForCat && fileForCat->IsValid()) { - osl::File aFile(fileForCat); - osl::File::RC aRC = aFile.open(osl_File_OpenFlag_Read); - if (aRC != osl::File::E_None) - { - std::cerr << "Error: Cannot read from temp file" << std::endl; - } - else + SvStream* aStream = fileForCat->GetStream(StreamMode::STD_READ); + while (aStream->good()) { - sal_Bool eof; - for (;;) + OString aStr; + aStream->ReadLine(aStr, SAL_MAX_INT32); + for (sal_Int32 i = 0; i < aStr.getLength(); ++i) { - aFile.isEndOfFile( &eof ); - if (eof) - break; - rtl::ByteSequence bseq; - aFile.readLine(bseq); - unsigned const char * aStr = reinterpret_cast<unsigned char const *>(bseq.getConstArray()); - for (sal_Int32 i = 0; i < bseq.getLength(); ++i) - { - std::cout << aStr[i]; - } - std::cout << std::endl; + std::cout << aStr[i]; } - aFile.close(); - osl::File::remove(fileForCat); + std::cout << std::endl; } } } |