Utils: Introduce FilePath::ensureWritableDir()

Combine the test and potential creation in one operation to potentially
reduce the number of remote calls.

Change-Id: I06ffa1256593afec430eb35605ba3b249f1da97c
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
hjk
2021-05-31 18:20:46 +02:00
parent 2672bb2930
commit c2bc7b8d3c
5 changed files with 28 additions and 0 deletions

View File

@@ -793,6 +793,18 @@ bool FilePath::isWritableDir() const
return exists() && fi.isDir() && fi.isWritable();
}
bool FilePath::ensureWritableDir() const
{
if (needsDevice()) {
QTC_ASSERT(s_deviceHooks.ensureWritableDir, return false);
return s_deviceHooks.ensureWritableDir(*this);
}
const QFileInfo fi{m_data};
if (exists() && fi.isDir() && fi.isWritable())
return true;
return QDir().mkpath(m_data);
}
bool FilePath::isExecutableFile() const
{
if (needsDevice()) {