[Libreoffice-commits] core.git: desktop/source

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Tue Jan 15 07:39:45 UTC 2019


 desktop/source/app/dispatchwatcher.cxx |   41 ++++++++++++---------------------
 1 file changed, 15 insertions(+), 26 deletions(-)

New commits:
commit a975d17e715bcf317e40d19ef47cc37660b81f7e
Author:     Mike Kaganski <mike.kaganski at collabora.com>
AuthorDate: Tue Jan 15 07:22:37 2019 +0100
Commit:     Mike Kaganski <mike.kaganski at collabora.com>
CommitDate: Tue Jan 15 08:39:23 2019 +0100

    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 at collabora.com>

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;
                                     }
                                 }
                             }


More information about the Libreoffice-commits mailing list