summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2024-02-19 16:09:29 +0600
committerMike Kaganski <mike.kaganski@collabora.com>2024-02-20 06:51:42 +0100
commit3da833827bd3efae2b5e0911cd6e2dd961c3ad89 (patch)
treee68566010850e2ad0171165ceb22559dce6e12d4 /unotools
parentef9e1116d1100af50d7b74dcee5155c81b7b50fb (diff)
Simplify by replacing ensuredir with osl::Directory::createPath
Change-Id: I3c60814de88ce126f192fd176142dd003af33d9d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/163588 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'unotools')
-rw-r--r--unotools/source/ucbhelper/tempfile.cxx74
1 files changed, 6 insertions, 68 deletions
diff --git a/unotools/source/ucbhelper/tempfile.cxx b/unotools/source/ucbhelper/tempfile.cxx
index 7a02c6bba7b1..3b2a7c604b4c 100644
--- a/unotools/source/ucbhelper/tempfile.cxx
+++ b/unotools/source/ucbhelper/tempfile.cxx
@@ -60,64 +60,9 @@ OUString stripTrailingSlash(const OUString& url)
return url;
}
-OUString getParentName( std::u16string_view aFileName )
+bool okOrExists(osl::FileBase::RC ret)
{
- size_t lastIndex = aFileName.rfind( '/' );
- OUString aParent;
-
- if (lastIndex != std::u16string_view::npos)
- {
- aParent = aFileName.substr(0, lastIndex);
-
- if (aParent.endsWith(":") && aParent.getLength() == 6)
- aParent += "/";
-
- if (aParent.equalsIgnoreAsciiCase("file://"))
- aParent = "file:///";
- }
-
- return aParent;
-}
-
-bool ensuredir( const OUString& rUnqPath )
-{
- OUString aPath;
- if ( rUnqPath.isEmpty() )
- return false;
-
- // remove trailing slash
- aPath = stripTrailingSlash(rUnqPath);
-
- // HACK: create directory on a mount point with nobrowse option
- // returns ENOSYS in any case !!
- osl::Directory aDirectory( aPath );
- osl::FileBase::RC nError = aDirectory.open();
- aDirectory.close();
- if( nError == osl::File::E_None )
- return true;
-
- // try to create the directory
- nError = osl::Directory::create( aPath );
- bool bSuccess = ( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST );
- if( !bSuccess )
- {
- // perhaps parent(s) don't exist
- OUString aParentDir = getParentName( aPath );
- if ( aParentDir != aPath )
- {
- bSuccess = ensuredir( getParentName( aPath ) );
-
- // After parent directory structure exists try it one's more
- if ( bSuccess )
- {
- // Parent directory exists, retry creation of directory
- nError = osl::Directory::create( aPath );
- bSuccess =( nError == osl::File::E_None || nError == osl::FileBase::E_EXIST );
- }
- }
- }
-
- return bSuccess;
+ return ret == osl::FileBase::E_None || ret == osl::FileBase::E_EXIST;
}
const OUString& getTempNameBase_Impl()
@@ -129,7 +74,7 @@ const OUString& getTempNameBase_Impl()
if (rc == osl::FileBase::E_None)
{
gTempNameBase_Impl = ensureTrailingSlash(ustrTempDirURL);
- ensuredir(gTempNameBase_Impl);
+ osl::Directory::createPath(gTempNameBase_Impl);
}
}
assert(gTempNameBase_Impl.isEmpty() || gTempNameBase_Impl.endsWith("/"));
@@ -171,7 +116,7 @@ OUString ConstructTempDir_Impl( const OUString* pParent, bool bCreateParentDirs
{
// if no parent or invalid parent : use default directory
aName = getTempNameBase_Impl();
- ensuredir(aName); // tdf#159769: always make sure it exists
+ osl::Directory::createPath(aName); // tdf#159769: always make sure it exists
}
// Make sure that directory ends with a separator
@@ -268,8 +213,7 @@ OUString lcl_createName(
else
aDirName = aName;
TempDirCreatedObserver observer;
- osl::FileBase::RC err = osl::Directory::createPath(aDirName, &observer);
- if (err != osl::FileBase::E_None && err != osl::FileBase::E_EXIST)
+ if (!okOrExists(osl::Directory::createPath(aDirName, &observer)))
return OUString();
}
aName += rLeadingChars;
@@ -549,13 +493,7 @@ OUString SetTempNameBaseDirectory( const OUString &rBaseName )
OUString aUnqPath(stripTrailingSlash(rBaseName));
// try to create the directory
- bool bRet = false;
- osl::FileBase::RC err = osl::Directory::create( aUnqPath );
- if (err != osl::FileBase::E_None && err != osl::FileBase::E_EXIST)
- // perhaps parent(s) don't exist
- bRet = ensuredir( aUnqPath );
- else
- bRet = true;
+ bool bRet = okOrExists(osl::Directory::createPath(aUnqPath));
// failure to create base directory means returning an empty string
OUString aTmp;