From 419d18c1284fc2560ca781d9f42a8a9c2c32b7e4 Mon Sep 17 00:00:00 2001 From: Klaas Freitag Date: Fri, 9 Oct 2015 13:02:02 +0200 Subject: [PATCH] FileSystem: Reuse the FileInfo object that is created in the caller. With that, a lot of stats can be avoided, ie. in SocketAPI --- src/gui/folder.cpp | 4 ++-- src/gui/socketapi.cpp | 4 ++-- src/libsync/filesystem.cpp | 13 ++++++++++--- src/libsync/filesystem.h | 3 ++- 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index e5d8c2c04..6aad7011c 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -156,7 +156,7 @@ void Folder::checkLocalPath() if( fi.isDir() && fi.isReadable() ) { qDebug() << "Checked local path ok"; } else { - if( !FileSystem::fileExists(_definition.localPath) ) { + if( !FileSystem::fileExists(_definition.localPath, fi) ) { // try to create the local dir QDir d(_definition.localPath); if( d.mkpath(_definition.localPath) ) { @@ -164,7 +164,7 @@ void Folder::checkLocalPath() } } // Check directory again - if( !FileSystem::fileExists(_definition.localPath) ) { + if( !FileSystem::fileExists(_definition.localPath, fi) ) { _syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_definition.localPath)); _syncResult.setStatus( SyncResult::SetupError ); } else if( !fi.isDir() ) { diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp index 152de1a73..ea2115575 100644 --- a/src/gui/socketapi.cpp +++ b/src/gui/socketapi.cpp @@ -517,7 +517,8 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa fileNameSlash += QLatin1Char('/'); } - if( !FileSystem::fileExists(file) ) { + const QFileInfo fi(file); + if( !FileSystem::fileExists(file, fi) ) { qDebug() << "OO File " << file << " is not existing"; return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR); } @@ -525,7 +526,6 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa // file is ignored? // Qt considers .lnk files symlinks on Windows so we need to work // around that here. - const QFileInfo fi(file); if( fi.isSymLink() #ifdef Q_OS_WIN && fi.suffix() != "lnk" diff --git a/src/libsync/filesystem.cpp b/src/libsync/filesystem.cpp index 4b9178b18..5420fd58a 100644 --- a/src/libsync/filesystem.cpp +++ b/src/libsync/filesystem.cpp @@ -403,7 +403,7 @@ static bool fileExistsWin(const QString& filename) } #endif -bool FileSystem::fileExists(const QString& filename) +bool FileSystem::fileExists(const QString& filename, const QFileInfo& fileInfo) { #ifdef Q_OS_WIN if (isLnkFile(filename)) { @@ -411,8 +411,15 @@ bool FileSystem::fileExists(const QString& filename) return fileExistsWin(filename); } #endif - QFileInfo file(filename); - return file.exists(); + bool re = fileInfo.exists(); + // if the filename is different from the filename in fileInfo, the fileInfo is + // not valid. There needs to be one initialised here. Otherwise the incoming + // fileInfo is re-used. + if( fileInfo.filePath() != filename ) { + QFileInfo myFI(filename); + re = myFI.exists(); + } + return re; } #ifdef Q_OS_WIN diff --git a/src/libsync/filesystem.h b/src/libsync/filesystem.h index 6b4b0ef8e..8a101cc34 100644 --- a/src/libsync/filesystem.h +++ b/src/libsync/filesystem.h @@ -18,6 +18,7 @@ #include #include #include +#include #include @@ -73,7 +74,7 @@ qint64 OWNCLOUDSYNC_EXPORT getSize(const QString& filename); * Use this over QFileInfo::exists() and QFile::exists() to avoid bugs with lnk * files, see above. */ -bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename); +bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename, const QFileInfo& = QFileInfo() ); /** * @brief Rename the file \a originFileName to \a destinationFileName. -- 2.30.2