FileSystem: Reuse the FileInfo object that is created in the caller.
authorKlaas Freitag <freitag@owncloud.com>
Fri, 9 Oct 2015 11:02:02 +0000 (13:02 +0200)
committerKlaas Freitag <freitag@owncloud.com>
Fri, 9 Oct 2015 11:02:02 +0000 (13:02 +0200)
With that, a lot of stats can be avoided, ie. in SocketAPI

src/gui/folder.cpp
src/gui/socketapi.cpp
src/libsync/filesystem.cpp
src/libsync/filesystem.h

index e5d8c2c04fdb3b1258bda52a8724cfd3a5b9d877..6aad7011cee3b8f1d669a44aac1a7845e44d3c43 100644 (file)
@@ -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() ) {
index 152de1a73f3933dc9eef61800cb623eb1afd5638..ea2115575b2b248f0fdb134698b2f6ec112c4b4f 100644 (file)
@@ -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"
index 4b9178b18c73ab725ccd46ccbae14120b71feaf8..5420fd58a09b2ce79438c10ff944aedc42634835 100644 (file)
@@ -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
index 6b4b0ef8e4696ca063209df2e667b4017585c73c..8a101cc34cac44076c6087ccad7df39a5549d8e4 100644 (file)
@@ -18,6 +18,7 @@
 #include <QString>
 #include <ctime>
 #include <QCryptographicHash>
+#include <QFileInfo>
 
 #include <owncloudlib.h>
 
@@ -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.