forked from qt-creator/qt-creator
Utils: Add/fix FilePath::isFile and FilePath::isDir
In general, the more specific isReadableFile etc are preferred, but for porting a 1:1 match to QFileInfo functionality is helpful. Change-Id: I5b575ca9a5053f13f63c0fbe0e3dcc222494280f Reviewed-by: David Schulz <david.schulz@qt.io>
This commit is contained in:
@@ -939,6 +939,26 @@ bool FilePath::isReadableDir() const
|
||||
return fi.exists() && fi.isReadable() && fi.isDir();
|
||||
}
|
||||
|
||||
bool FilePath::isFile() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.isFile, return false);
|
||||
return s_deviceHooks.isFile(*this);
|
||||
}
|
||||
const QFileInfo fi{m_data};
|
||||
return fi.exists() && fi.isFile();
|
||||
}
|
||||
|
||||
bool FilePath::isDir() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
QTC_ASSERT(s_deviceHooks.isDir, return false);
|
||||
return s_deviceHooks.isDir(*this);
|
||||
}
|
||||
const QFileInfo fi{m_data};
|
||||
return fi.exists() && fi.isDir();
|
||||
}
|
||||
|
||||
bool FilePath::createDir() const
|
||||
{
|
||||
if (needsDevice()) {
|
||||
@@ -1244,12 +1264,6 @@ bool FilePath::endsWith(const QString &s) const
|
||||
return m_data.endsWith(s, caseSensitivity());
|
||||
}
|
||||
|
||||
bool FilePath::isDir() const
|
||||
{
|
||||
QTC_CHECK(m_scheme.isEmpty()); // FIXME: Not implemented yet.
|
||||
return QFileInfo(m_data).isDir();
|
||||
}
|
||||
|
||||
/// \returns the relativeChildPath of FilePath to parent if FilePath is a child of parent
|
||||
/// \note returns a empty FilePath if FilePath is not a child of parent
|
||||
/// That is, this never returns a path starting with "../"
|
||||
|
||||
Reference in New Issue
Block a user