summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-08-30 13:42:20 +0200
committerJan-Marek Glogowski <glogow@fbihome.de>2016-09-23 23:25:49 +0200
commit3c4dfb872d50413b605fb846dfdebd28947026e8 (patch)
treed8c53251254a416528ecdf6babb30a0bd7d71da4 /unotools
parent260cd3aeea2d02507dd131ee2028c4f48f7562f8 (diff)
tdf#94987 Create directories for temp filenames
Per default a temporary file is construted from a path and a leading pattern for the filename. For mail merge the filename can be read from a database column. If the path is not existing, a temporary directory is created. Normally the temp file function would fail, if the filename contains a slash and the sub-directory of the filename doesn't exists as a subdirectory of path. To implement tdf#94987, this adds an option to the temp file class to create the parent directories of the filename pattern. Change-Id: I02bf34294dac85598ee153d8cfcf00bc5d7775af
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx42
1 files changed, 37 insertions, 5 deletions
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index dcc4068b2ac3..fa2cbf567436 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -225,11 +225,39 @@ private:
sal_uInt32 UniqueTokens::globalValue = SAL_MAX_UINT32;
+namespace
+{
+ class TempDirCreatedObserver : public DirectoryCreationObserver
+ {
+ public:
+ virtual void DirectoryCreated(const rtl::OUString& aDirectoryUrl) override
+ {
+ File::setAttributes( aDirectoryUrl, osl_File_Attribute_OwnRead |
+ osl_File_Attribute_OwnWrite | osl_File_Attribute_OwnExe );
+ };
+ };
+};
+
OUString lcl_createName(
const OUString& rLeadingChars, Tokens & tokens, const OUString* pExtension,
- const OUString* pParent, bool bDirectory, bool bKeep, bool bLock)
+ const OUString* pParent, bool bDirectory, bool bKeep, bool bLock,
+ bool bCreateParentDirs )
{
- OUString aName = ConstructTempDir_Impl( pParent ) + rLeadingChars;
+ OUString aName = ConstructTempDir_Impl( pParent );
+ if ( bCreateParentDirs )
+ {
+ sal_Int32 nOffset = rLeadingChars.lastIndexOf("/");
+ if (-1 != nOffset)
+ {
+ OUString aDirName = aName + OUString( rLeadingChars.getStr(), nOffset );
+ TempDirCreatedObserver observer;
+ FileBase::RC err = Directory::createPath( aDirName, &observer );
+ if ( err != FileBase::E_None && err != FileBase::E_EXIST )
+ return OUString();
+ }
+ }
+ aName += rLeadingChars;
+
OUString token;
while (tokens.next(&token))
{
@@ -306,7 +334,8 @@ OUString CreateTempName_Impl( const OUString* pParent, bool bKeep, bool bDir = t
aEyeCatcher += aPidString;
#endif
UniqueTokens t;
- return lcl_createName(aEyeCatcher, t, nullptr, pParent, bDir, bKeep, false);
+ return lcl_createName( aEyeCatcher, t, nullptr, pParent, bDir, bKeep,
+ false, false);
}
OUString TempFile::CreateTempName()
@@ -328,13 +357,16 @@ TempFile::TempFile( const OUString* pParent, bool bDirectory )
aName = CreateTempName_Impl( pParent, true, bDirectory );
}
-TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero, const OUString* pExtension, const OUString* pParent)
+TempFile::TempFile( const OUString& rLeadingChars, bool _bStartWithZero,
+ const OUString* pExtension, const OUString* pParent,
+ bool bCreateParentDirs )
: pStream( nullptr )
, bIsDirectory( false )
, bKillingFileEnabled( false )
{
SequentialTokens t(_bStartWithZero);
- aName = lcl_createName(rLeadingChars, t, pExtension, pParent, false/*bDirectory*/, true, true);
+ aName = lcl_createName( rLeadingChars, t, pExtension, pParent, false,
+ true, true, bCreateParentDirs );
}
TempFile::~TempFile()