From 2736f42f76f0cc227b64c3214ddd9176ee090891 Mon Sep 17 00:00:00 2001 From: Ivailo Monev Date: Wed, 24 Nov 2021 20:08:58 +0200 Subject: [PATCH] replace QFile::exists() with QStatInfo::isFile() where possible Signed-off-by: Ivailo Monev --- src/core/plugin/qlibrary.cpp | 8 +++++--- src/declarative/qml/qdeclarativeimport.cpp | 14 ++++++-------- src/gui/dialogs/qfiledialog.cpp | 7 +++++-- src/gui/image/qicon.cpp | 2 +- src/gui/image/qiconloader.cpp | 13 ++++++++----- src/network/access/qnetworkdiskcache.cpp | 4 +++- src/network/socket/qlocalserver_unix.cpp | 6 +++--- 7 files changed, 31 insertions(+), 23 deletions(-) diff --git a/src/core/plugin/qlibrary.cpp b/src/core/plugin/qlibrary.cpp index 301efdd48..31294d824 100644 --- a/src/core/plugin/qlibrary.cpp +++ b/src/core/plugin/qlibrary.cpp @@ -39,6 +39,7 @@ #include "qvector.h" #include "qdir.h" #include "qfilesystementry_p.h" +#include "qcore_unix_p.h" #include @@ -268,7 +269,8 @@ QLibraryPrivate *QLibraryPrivate::findOrCreate(const QString &fileName, const QS if (!suffix.isEmpty() && name.endsWith(suffix)) continue; const QString attempt = path + prefix + name + suffix; - if (QFile::exists(attempt)) { + const QStatInfo statinfo(attempt); + if (statinfo.isFile()) { return new QLibraryPrivate(attempt, version); } } @@ -416,10 +418,10 @@ bool QLibraryPrivate::isPlugin() return false; } - QFileInfo fileinfo(fileName); + const QStatInfo statinfo(fileName); #ifndef QT_NO_DATESTRING - lastModified = fileinfo.lastModified().toString(Qt::ISODate); + lastModified = statinfo.lastModified().toString(Qt::ISODate); #endif QString regkey = QString::fromLatin1("Katie Plugin Cache %1/%2") .arg(QLatin1String(QT_VERSION_HEX_STR)) diff --git a/src/declarative/qml/qdeclarativeimport.cpp b/src/declarative/qml/qdeclarativeimport.cpp index 40fa8aca8..d5985700d 100644 --- a/src/declarative/qml/qdeclarativeimport.cpp +++ b/src/declarative/qml/qdeclarativeimport.cpp @@ -833,10 +833,9 @@ void QDeclarativeImportDatabase::addPluginPath(const QString& path) if (qmlImportTrace()) qDebug().nospace() << "QDeclarativeImportDatabase::addPluginPath: " << path; - QUrl url = QUrl(path); - if (url.isRelative() || url.scheme() == QLatin1String("file") - || (url.scheme().length() == 1 && QFile::exists(path)) ) { // windows path - QDir dir = QDir(path); + const QUrl url(path); + if (url.isRelative() || url.scheme() == QLatin1String("file")) { + const QDir dir(path); filePluginPath.prepend(dir.canonicalPath()); } else { filePluginPath.prepend(path); @@ -854,12 +853,11 @@ void QDeclarativeImportDatabase::addImportPath(const QString& path) if (path.isEmpty()) return; - QUrl url = QUrl(path); + const QUrl url(path); QString cPath; - if (url.isRelative() || url.scheme() == QLatin1String("file") - || (url.scheme().length() == 1 && QFile::exists(path)) ) { // windows path - QDir dir = QDir(path); + if (url.isRelative() || url.scheme() == QLatin1String("file")) { + const QDir dir(path); cPath = dir.canonicalPath(); } else { cPath = path; diff --git a/src/gui/dialogs/qfiledialog.cpp b/src/gui/dialogs/qfiledialog.cpp index 3fefe0c1f..718338728 100644 --- a/src/gui/dialogs/qfiledialog.cpp +++ b/src/gui/dialogs/qfiledialog.cpp @@ -39,6 +39,7 @@ #include "qstylepainter.h" #include "qcoreapplication_p.h" #include "qcorecommon_p.h" +#include "qcore_unix_p.h" #include "ui_qfiledialog.h" #include @@ -842,7 +843,8 @@ QStringList QFileDialogPrivate::typedFiles() const QString editText = lineEdit()->text(); if (!editText.contains(QLatin1Char('"'))) { const QString prefix = q->directory().absolutePath() + QDir::separator(); - if (QFile::exists(prefix + editText)) + const QStatInfo statinfo(prefix + editText); + if (statinfo.isFile()) files << editText; else files << qt_tildeExpansion(editText); @@ -855,7 +857,8 @@ QStringList QFileDialogPrivate::typedFiles() const continue; // Every even token is a separator const QString token = tokens.at(i); const QString prefix = q->directory().absolutePath() + QDir::separator(); - if (QFile::exists(prefix + token)) + const QStatInfo statinfo(prefix + token); + if (statinfo.isFile()) files << token; else files << qt_tildeExpansion(token); diff --git a/src/gui/image/qicon.cpp b/src/gui/image/qicon.cpp index 1d35fd1c7..56ad2524f 100644 --- a/src/gui/image/qicon.cpp +++ b/src/gui/image/qicon.cpp @@ -80,7 +80,7 @@ typedef QCache IconCache; Q_GLOBAL_STATIC(IconCache, qtIconCache) QIconPrivate::QIconPrivate() - : engine(0), ref(1), + : engine(nullptr), ref(1), serialNum(serialNumCounter.fetchAndAddRelaxed(1)), detach_no(0) { diff --git a/src/gui/image/qiconloader.cpp b/src/gui/image/qiconloader.cpp index 5f790b5f4..5e4538a41 100644 --- a/src/gui/image/qiconloader.cpp +++ b/src/gui/image/qiconloader.cpp @@ -25,7 +25,9 @@ #include "qicon_p.h" #include "qguiplatformplugin.h" #include "qfactoryloader_p.h" +#include "qstylehelper_p.h" #include "qguicommon_p.h" +#include "qcore_unix_p.h" #include #include @@ -37,8 +39,6 @@ #include #include -#include "qstylehelper_p.h" - #include QT_BEGIN_NAMESPACE @@ -111,7 +111,8 @@ QIconTheme::QIconTheme(const QString &themeName) { foreach (const QString &it, QIcon::themeSearchPaths()) { QString themeDir = it + QLatin1Char('/') + themeName; - if (QFile::exists(themeDir + QLatin1String("/index.theme"))) { + const QStatInfo statinfo(themeDir + QLatin1String("/index.theme")); + if (statinfo.isFile()) { m_contentDir = themeDir; m_valid = true; break; @@ -190,7 +191,8 @@ QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName, foreach (const QIconDirInfo &dirInfo, theme.keyList()) { const QString subDir = contentDir + dirInfo.path + QLatin1Char('/'); const QString pngPath = subDir + iconName + QLatin1String(".png"); - if (QFile::exists(pngPath)) { + const QStatInfo pnginfo(pngPath); + if (pnginfo.isFile()) { PixmapEntry *iconEntry = new PixmapEntry; iconEntry->dir = dirInfo; iconEntry->filename = pngPath; @@ -199,7 +201,8 @@ QThemeIconEntries QIconLoader::findIconHelper(const QString &themeName, entries.prepend(iconEntry); } else if (m_supportsSvg) { const QString svgPath = subDir + iconName + QLatin1String(".svg"); - if (QFile::exists(svgPath)) { + const QStatInfo svginfo(pngPath); + if (svginfo.isFile()) { ScalableEntry *iconEntry = new ScalableEntry; iconEntry->dir = dirInfo; iconEntry->filename = svgPath; diff --git a/src/network/access/qnetworkdiskcache.cpp b/src/network/access/qnetworkdiskcache.cpp index bb9cb5da4..44d91f152 100644 --- a/src/network/access/qnetworkdiskcache.cpp +++ b/src/network/access/qnetworkdiskcache.cpp @@ -33,6 +33,7 @@ #include "qcryptographichash.h" #include "qdebug.h" #include "qcorecommon_p.h" +#include "qcore_unix_p.h" #define CACHE_POSTFIX QLatin1String(".d") #define PREPARED_SLASH QLatin1String("prepared/") @@ -255,7 +256,8 @@ void QNetworkDiskCachePrivate::storeItem(QCacheItem *cacheItem) QString fileName = cacheFileName(cacheItem->metaData.url()); Q_ASSERT(!fileName.isEmpty()); - if (QFile::exists(fileName)) { + const QStatInfo statinfo(fileName); + if (statinfo.isFile()) { if (!QFile::remove(fileName)) { qWarning() << "QNetworkDiskCache: couldn't remove the cache file " << fileName; return; diff --git a/src/network/socket/qlocalserver_unix.cpp b/src/network/socket/qlocalserver_unix.cpp index 18657bfa3..7f9294d6d 100644 --- a/src/network/socket/qlocalserver_unix.cpp +++ b/src/network/socket/qlocalserver_unix.cpp @@ -44,10 +44,10 @@ bool QLocalServerPrivate::removeServer(const QString &name) } else { fileName = QDir::tempPath() + QLatin1Char('/') + name; } - if (QFile::exists(fileName)) + const QStatInfo statinfo(fileName); + if (statinfo.isFile()) return QFile::remove(fileName); - else - return true; + return true; } bool QLocalServerPrivate::listen(const QString &requestedServerName) -- 2.11.0