Kaydet (Commit) a975d17e authored tarafından Mike Kaganski's avatar Mike Kaganski

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: 's avatarMike Kaganski <mike.kaganski@collabora.com>
üst 23a8d5ff
......@@ -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;
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment