[Libreoffice-commits] core.git: 4 commits - desktop/source include/unotools sw/source unotools/source

Stephan Bergmann sbergman at redhat.com
Tue May 13 10:27:32 PDT 2014


 desktop/source/deployment/registry/dp_backend.cxx |    2 
 include/unotools/tempfile.hxx                     |   13 -
 sw/source/ui/dbui/mmoutputpage.cxx                |    2 
 unotools/source/ucbhelper/tempfile.cxx            |  201 +++++++---------------
 4 files changed, 73 insertions(+), 145 deletions(-)

New commits:
commit fcf455d4efde077bb2b092b607de12ebfc350275
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue May 13 19:04:50 2014 +0200

    Consolidate CreateTempName_Impl and lcl_createName
    
    Change-Id: I4dbb917a6d9343f797859a2f24fa1d92b26a51eb

diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 098c422..54799fd 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -159,92 +159,23 @@ OUString ConstructTempDir_Impl( const OUString* pParent )
     return aName;
 }
 
-void CreateTempName_Impl( OUString& rName, bool bKeep, bool bDir = true )
+OUString lcl_createName(
+    const OUString& rLeadingChars, unsigned long nSeed, bool bFirst,
+    const OUString* pExtension, const OUString* pParent, bool bDirectory,
+    bool bKeep)
 {
-    // add a suitable tempname
     // 36 ** 6 == 2176782336
     unsigned const nRadix = 36;
     unsigned long const nMax = (nRadix*nRadix*nRadix*nRadix*nRadix*nRadix);
-    OUString aName;
-    OUString aEyeCatcher = "lu";
-#ifdef DBG_UTIL
-#ifdef UNX
-    const char* eye = getenv("LO_TESTNAME");
-    if(eye)
-    {
-        aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
-    }
-#endif
-#endif
-    aName = rName + aEyeCatcher;
-    rName = "";
-    static unsigned long u = Time::GetSystemTicks() % nMax;
-    for ( unsigned long nSeed = u; ++u != nSeed; )
-    {
-        u %= nMax;
-        OUString aTmp( aName );
-        aTmp += OUString::number(u, nRadix);
-        aTmp += ".tmp";
-
-        if ( bDir )
-        {
-            FileBase::RC err = Directory::create( aTmp );
-            if ( err == FileBase::E_None )
-            {
-                // !bKeep: only for creating a name, not a file or directory
-                if ( bKeep || Directory::remove( aTmp ) == FileBase::E_None )
-                    rName = aTmp;
-                break;
-            }
-            else if ( err != FileBase::E_EXIST )
-            {
-                // if f.e. name contains invalid chars stop trying to create dirs
-                break;
-            }
-        }
-        else
-        {
-            DBG_ASSERT( bKeep, "Too expensive, use directory for creating name!" );
-            File aFile( aTmp );
-#ifdef UNX /* RW permission for the user only! */
-            mode_t old_mode = umask(077);
-#endif
-            FileBase::RC err = aFile.open( osl_File_OpenFlag_Create | osl_File_OpenFlag_NoLock );
-#ifdef UNX
-            umask(old_mode);
-#endif
-            if (  err == FileBase::E_None )
-            {
-                rName = aTmp;
-                aFile.close();
-                break;
-            }
-            else if ( err != FileBase::E_EXIST )
-            {
-                 // if f.e. name contains invalid chars stop trying to create files
-                 // but if there is a folder with such name proceed further
-
-                 DirectoryItem aTmpItem;
-                 FileStatus aTmpStatus( osl_FileStatus_Mask_Type );
-                 if ( DirectoryItem::get( aTmp, aTmpItem ) != FileBase::E_None
-                   || aTmpItem.getFileStatus( aTmpStatus ) != FileBase::E_None
-                   || aTmpStatus.getFileType() != FileStatus::Directory )
-                     break;
-            }
-        }
-    }
-}
+    nSeed %= nMax;
 
-OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
-                    const OUString* pExtension, const OUString* pParent, bool bDirectory)
-{
     // get correct directory
     OUString aName = ConstructTempDir_Impl( pParent );
 
-    bool bUseNumber = _bStartWithZero;
+    bool bUseNumber = bFirst;
     // now use special naming scheme ( name takes leading chars and an index counting up from zero
     aName += rLeadingChars;
-    for ( sal_Int32 i=0;; i++ )
+    for ( unsigned long i=nSeed;; )
     {
         OUString aTmp( aName );
         if ( bUseNumber )
@@ -259,7 +190,11 @@ OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
             FileBase::RC err = Directory::create( aTmp );
             if ( err == FileBase::E_None )
             {
-                return aTmp;
+                // !bKeep: only for creating a name, not a file or directory
+                if ( bKeep || Directory::remove( aTmp ) == FileBase::E_None )
+                    return aTmp;
+                else
+                    return OUString();
             }
             else if ( err != FileBase::E_EXIST )
                 // if f.e. name contains invalid chars stop trying to create dirs
@@ -267,6 +202,7 @@ OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
         }
         else
         {
+            DBG_ASSERT( bKeep, "Too expensive, use directory for creating name!" );
             File aFile( aTmp );
 #ifdef UNX
             /* RW permission for the user only! */
@@ -294,16 +230,32 @@ OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
                     return OUString();
             }
         }
+        i = (i + 1) % nMax;
+        if (i == nSeed) {
+            return OUString();
+        }
     }
 }
 
-OUString TempFile::CreateTempName()
+OUString CreateTempName_Impl( const OUString* pParent, bool bKeep, bool bDir = true )
 {
-    // get correct directory
-    OUString aName = ConstructTempDir_Impl( 0 );
+    OUString aEyeCatcher = "lu";
+#ifdef DBG_UTIL
+#ifdef UNX
+    const char* eye = getenv("LO_TESTNAME");
+    if(eye)
+    {
+        aEyeCatcher = OUString(eye, strlen(eye), RTL_TEXTENCODING_ASCII_US);
+    }
+#endif
+#endif
+    return lcl_createName(
+        aEyeCatcher, Time::GetSystemTicks(), true, 0, pParent, bDir, bKeep);
+}
 
-    // get TempFile name with default naming scheme
-    CreateTempName_Impl( aName, false );
+OUString TempFile::CreateTempName()
+{
+    OUString aName(CreateTempName_Impl( 0, false ));
 
     // convert to file URL
     OUString aTmp;
@@ -317,11 +269,7 @@ TempFile::TempFile( const OUString* pParent, bool bDirectory )
     , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    // get correct directory
-    aName = ConstructTempDir_Impl( pParent );
-
-    // get TempFile with default naming scheme
-    CreateTempName_Impl( aName, true, bDirectory );
+    aName = CreateTempName_Impl( pParent, true, bDirectory );
 }
 
 TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension, const OUString* pParent, bool bDirectory)
@@ -329,14 +277,14 @@ TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension, c
     , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    aName = lcl_createName(rLeadingChars, true, pExtension, pParent, bDirectory);
+    aName = lcl_createName(rLeadingChars, 0, true, pExtension, pParent, bDirectory, true);
 }
 TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero, const OUString* pExtension, const OUString* pParent, bool bDirectory)
     : pStream( 0 )
     , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    aName = lcl_createName(rLeadingChars, _bStartWithZero, pExtension, pParent, bDirectory);
+    aName = lcl_createName(rLeadingChars, 0, _bStartWithZero, pExtension, pParent, bDirectory, true);
 }
 
 TempFile::~TempFile()
commit b7e05063cba799c5df9aca8ff6be81927868e7d9
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue May 13 18:18:29 2014 +0200

    Remove nonsensical code
    
    ...introduced with 2d8c990f8790be43cf4dda4bc871a917b9dcc974 "INTEGRATION:
    CWS reportdesign01: #i79214# new method to allow to start not with zero."
    
    Change-Id: Id141b2913ceb47c0c54f4449bdcdf5130c6f355b

diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index b0b6b3e..098c422 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -294,8 +294,6 @@ OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
                     return OUString();
             }
         }
-        if ( !_bStartWithZero )
-            aTmp += OUString::number( i );
     }
 }
 
commit a699927c563b6448014e6e96c71d0eb9714136d7
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue May 13 18:17:54 2014 +0200

    Elide utl::TempFile_Impl
    
    Change-Id: I8f14cd351c17abaa9d48144cdf8325afc250787b

diff --git a/desktop/source/deployment/registry/dp_backend.cxx b/desktop/source/deployment/registry/dp_backend.cxx
index d437a46..076e4dd 100644
--- a/desktop/source/deployment/registry/dp_backend.cxx
+++ b/desktop/source/deployment/registry/dp_backend.cxx
@@ -221,7 +221,7 @@ OUString PackageRegistryBackend::createFolder(
     ::dp_misc::create_folder(&dataContent, sDataFolder, xCmdEnv);
 
     const OUString baseDir(sDataFolder);
-    const ::utl::TempFile aTemp(&baseDir, true);
+    ::utl::TempFile aTemp(&baseDir, true);
     const OUString url = aTemp.GetURL();
     return sDataFolder + url.copy(url.lastIndexOf('/'));
 }
diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx
index 659cdc7..3299e58 100644
--- a/include/unotools/tempfile.hxx
+++ b/include/unotools/tempfile.hxx
@@ -26,8 +26,6 @@
 namespace utl
 {
 
-struct TempFile_Impl;
-
 /**
     The class TempFile gives access to temporary files in the local file system. Sometimes they are needed because a 3rd party
     code has a file name based interface, or some file access has to be done locally without transferring tons of bytes to or
@@ -46,8 +44,11 @@ struct TempFile_Impl;
 
 class UNOTOOLS_DLLPUBLIC TempFile
 {
-    TempFile_Impl*  pImp;
-    bool            bKillingFileEnabled;
+    OUString    aName;
+    OUString    aURL;
+    SvStream*   pStream;
+    bool        bIsDirectory;
+    bool        bKillingFileEnabled;
 
     // prevent copy c'tor
     TempFile( const TempFile& );
@@ -99,7 +100,7 @@ public:
                     If no UCP is available for the local file system, an empty URL is returned. In this case you can't access
                     the file as a UCB content !
                     */
-    OUString        GetURL() const;
+    OUString        GetURL();
 
                     /**
                     Returns the "physical" name of the tempfile in host notation ( should only be used for 3rd party code
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index be2b8a1..b0b6b3e 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -47,20 +47,6 @@ namespace
 namespace utl
 {
 
-struct TempFile_Impl
-{
-    OUString    aName;
-    OUString    aURL;
-    SvStream*   pStream;
-    bool        bIsDirectory;
-
-    TempFile_Impl()
-        : pStream(0)
-        , bIsDirectory(false)
-    {
-    }
-};
-
 OUString getParentName( const OUString& aFileName )
 {
     sal_Int32 lastIndex = aFileName.lastIndexOf( '/' );
@@ -249,11 +235,9 @@ void CreateTempName_Impl( OUString& rName, bool bKeep, bool bDir = true )
     }
 }
 
-void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars, bool _bStartWithZero,
+OUString lcl_createName(const OUString& rLeadingChars, bool _bStartWithZero,
                     const OUString* pExtension, const OUString* pParent, bool bDirectory)
 {
-    _rImpl.bIsDirectory = bDirectory;
-
     // get correct directory
     OUString aName = ConstructTempDir_Impl( pParent );
 
@@ -275,12 +259,11 @@ void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars, bool _b
             FileBase::RC err = Directory::create( aTmp );
             if ( err == FileBase::E_None )
             {
-                _rImpl.aName = aTmp;
-                break;
+                return aTmp;
             }
             else if ( err != FileBase::E_EXIST )
                 // if f.e. name contains invalid chars stop trying to create dirs
-                break;
+                return OUString();
         }
         else
         {
@@ -295,9 +278,8 @@ void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars, bool _b
 #endif
             if ( err == FileBase::E_None || err == FileBase::E_NOLCK )
             {
-                _rImpl.aName = aTmp;
                 aFile.close();
-                break;
+                return aTmp;
             }
             else if ( err != FileBase::E_EXIST )
             {
@@ -309,7 +291,7 @@ void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars, bool _b
                 if ( DirectoryItem::get( aTmp, aTmpItem ) != FileBase::E_None
                   || aTmpItem.getFileStatus( aTmpStatus ) != FileBase::E_None
                   || aTmpStatus.getFileType() != FileStatus::Directory )
-                    break;
+                    return OUString();
             }
         }
         if ( !_bStartWithZero )
@@ -333,93 +315,92 @@ OUString TempFile::CreateTempName()
 }
 
 TempFile::TempFile( const OUString* pParent, bool bDirectory )
-    : pImp( new TempFile_Impl )
+    : pStream( 0 )
+    , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    pImp->bIsDirectory = bDirectory;
-
     // get correct directory
-    pImp->aName = ConstructTempDir_Impl( pParent );
+    aName = ConstructTempDir_Impl( pParent );
 
     // get TempFile with default naming scheme
-    CreateTempName_Impl( pImp->aName, true, bDirectory );
+    CreateTempName_Impl( aName, true, bDirectory );
 }
 
 TempFile::TempFile( const OUString& rLeadingChars, const OUString* pExtension, const OUString* pParent, bool bDirectory)
-    : pImp( new TempFile_Impl )
+    : pStream( 0 )
+    , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    lcl_createName(*pImp, rLeadingChars, true, pExtension, pParent, bDirectory);
+    aName = lcl_createName(rLeadingChars, true, pExtension, pParent, bDirectory);
 }
 TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero, const OUString* pExtension, const OUString* pParent, bool bDirectory)
-    : pImp( new TempFile_Impl )
+    : pStream( 0 )
+    , bIsDirectory( bDirectory )
     , bKillingFileEnabled( false )
 {
-    lcl_createName(*pImp, rLeadingChars, _bStartWithZero, pExtension, pParent, bDirectory);
+    aName = lcl_createName(rLeadingChars, _bStartWithZero, pExtension, pParent, bDirectory);
 }
 
 TempFile::~TempFile()
 {
-    delete pImp->pStream;
+    delete pStream;
     if ( bKillingFileEnabled )
     {
-        if ( pImp->bIsDirectory )
+        if ( bIsDirectory )
         {
             // at the moment no recursiv algorithm present
-            Directory::remove( pImp->aName );
+            Directory::remove( aName );
         }
         else
         {
-            File::remove( pImp->aName );
+            File::remove( aName );
         }
     }
-
-    delete pImp;
 }
 
 bool TempFile::IsValid() const
 {
-    return !(pImp->aName.isEmpty());
+    return !aName.isEmpty();
 }
 
 OUString TempFile::GetFileName() const
 {
     OUString aTmp;
-    FileBase::getSystemPathFromFileURL( pImp->aName, aTmp );
+    FileBase::getSystemPathFromFileURL( aName, aTmp );
     return aTmp;
 }
 
-OUString TempFile::GetURL() const
+OUString TempFile::GetURL()
 {
-    if ( pImp->aURL.isEmpty() )
+    if ( aURL.isEmpty() )
     {
         OUString aTmp;
         LocalFileHelper::ConvertPhysicalNameToURL( GetFileName(), aTmp );
-        pImp->aURL = aTmp;
+        aURL = aTmp;
     }
 
-    return pImp->aURL;
+    return aURL;
 }
 
 SvStream* TempFile::GetStream( StreamMode eMode )
 {
-    if ( !pImp->pStream )
+    if ( !pStream )
     {
         if ( !GetURL().isEmpty() )
-            pImp->pStream = UcbStreamHelper::CreateStream( pImp->aURL, eMode, true /* bFileExists */ );
+            pStream = UcbStreamHelper::CreateStream( aURL, eMode, true /* bFileExists */ );
         else
-            pImp->pStream = new SvMemoryStream( eMode );
+            pStream = new SvMemoryStream( eMode );
     }
 
-    return pImp->pStream;
+    return pStream;
 }
 
 void TempFile::CloseStream()
 {
-    if ( pImp->pStream )
+    if ( pStream )
     {
-        delete pImp->pStream;
-        pImp->pStream = NULL;
+        delete pStream;
+        pStream = NULL;
     }
 }
 
@@ -456,7 +437,7 @@ OUString TempFile::SetTempNameBaseDirectory( const OUString &rBaseName )
         TempFile aBase( NULL, true );
         if ( aBase.IsValid() )
             // use it in case of success
-            rTempNameBase_Impl = aBase.pImp->aName;
+            rTempNameBase_Impl = aBase.aName;
 
         // return system path of used directory
         FileBase::getSystemPathFromFileURL( rTempNameBase_Impl, aTmp );
commit 404e4d613ed62ee03b05db73b7e7783f5bccda12
Author: Stephan Bergmann <sbergman at redhat.com>
Date:   Tue May 13 15:09:10 2014 +0200

    utl::TempFile::CreateTempName pParent is unused
    
    Change-Id: Ide12ea21104af678dc541ed0e83970e7a2f5e694

diff --git a/include/unotools/tempfile.hxx b/include/unotools/tempfile.hxx
index 26c0581..659cdc7 100644
--- a/include/unotools/tempfile.hxx
+++ b/include/unotools/tempfile.hxx
@@ -136,7 +136,7 @@ public:
                     If you want to convert file name into a URL, always use class LocalFileHelper, but never use any
                     conversion functions of osl.
                     */
-    static OUString CreateTempName( const OUString* pParent=NULL );
+    static OUString CreateTempName();
 
                     /**
                     The TempNameBaseDirectory is a subfolder in the folder that is passed as a "physical" file name in the
diff --git a/sw/source/ui/dbui/mmoutputpage.cxx b/sw/source/ui/dbui/mmoutputpage.cxx
index c276b4b..1e9da5f 100644
--- a/sw/source/ui/dbui/mmoutputpage.cxx
+++ b/sw/source/ui/dbui/mmoutputpage.cxx
@@ -1093,7 +1093,7 @@ IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
         //then save it
         SfxStringItem aName(SID_FILE_NAME,
                 URIHelper::SmartRel2Abs(
-                    INetURLObject(), utl::TempFile::CreateTempName(0),
+                    INetURLObject(), utl::TempFile::CreateTempName(),
                     URIHelper::GetMaybeFileHdl()) );
 
         {
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 6053677..be2b8a1 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -317,10 +317,10 @@ void lcl_createName(TempFile_Impl& _rImpl,const OUString& rLeadingChars, bool _b
     }
 }
 
-OUString TempFile::CreateTempName( const OUString* pParent )
+OUString TempFile::CreateTempName()
 {
     // get correct directory
-    OUString aName = ConstructTempDir_Impl( pParent );
+    OUString aName = ConstructTempDir_Impl( 0 );
 
     // get TempFile name with default naming scheme
     CreateTempName_Impl( aName, false );


More information about the Libreoffice-commits mailing list