[Pkg-owncloud-commits] [owncloud-client] 57/484: FileSystem: Reuse the FileInfo object that is created in the caller.

Sandro Knauß hefee-guest at moszumanska.debian.org
Wed Dec 16 00:37:12 UTC 2015


This is an automated email from the git hooks/post-receive script.

hefee-guest pushed a commit to branch master
in repository owncloud-client.

commit 419d18c1284fc2560ca781d9f42a8a9c2c32b7e4
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Oct 9 13:02:02 2015 +0200

    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 e5d8c2c..6aad701 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 152de1a..ea21155 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 4b9178b..5420fd5 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 6b4b0ef..8a101cc 100644
--- a/src/libsync/filesystem.h
+++ b/src/libsync/filesystem.h
@@ -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.

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud-client.git



More information about the Pkg-owncloud-commits mailing list