[Pkg-owncloud-commits] [owncloud-client] 76/164: FileSystem: Remove QFileInfo based implementations.

Sandro Knauß hefee-guest at moszumanska.debian.org
Sun Mar 22 11:56:55 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 05624e3fc81859d821b2d90e4c89a0adef0dd2b7
Author: Klaas Freitag <freitag at owncloud.com>
Date:   Fri Feb 27 15:27:49 2015 +0100

    FileSystem: Remove QFileInfo based implementations.
    
    QFileInfo has to be refreshed if the underlying file has been
    modified in between. That is dangerous so ckamm and me decided
    to eliminate the QFileInfo based implementations.
    
    This was triggered by a bug that the client uploaded files that
    it should not have.
---
 src/gui/folder.cpp                |  6 +++---
 src/gui/socketapi.cpp             |  5 ++---
 src/libsync/filesystem.cpp        | 22 ----------------------
 src/libsync/filesystem.h          |  2 --
 src/libsync/propagatedownload.cpp |  4 ++--
 src/libsync/propagateupload.cpp   | 23 ++++++++++++-----------
 src/libsync/propagatorjobs.cpp    |  2 +-
 7 files changed, 20 insertions(+), 44 deletions(-)

diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp
index 25fdeb8..0b37518 100644
--- a/src/gui/folder.cpp
+++ b/src/gui/folder.cpp
@@ -146,12 +146,12 @@ AccountState* Folder::accountState() const
 
 void Folder::checkLocalPath()
 {
-    QFileInfo fi(_path);
+    const QFileInfo fi(_path);
 
     if( fi.isDir() && fi.isReadable() ) {
         qDebug() << "Checked local path ok";
     } else {
-        if( !FileSystem::fileExists(fi) ) {
+        if( !FileSystem::fileExists(_path) ) {
             // try to create the local dir
             QDir d(_path);
             if( d.mkpath(_path) ) {
@@ -159,7 +159,7 @@ void Folder::checkLocalPath()
             }
         }
         // Check directory again
-        if( !FileSystem::fileExists(fi) ) {
+        if( !FileSystem::fileExists(_path) ) {
             _syncResult.setErrorString(tr("Local folder %1 does not exist.").arg(_path));
             _syncResult.setStatus( SyncResult::SetupError );
         } else if( !fi.isDir() ) {
diff --git a/src/gui/socketapi.cpp b/src/gui/socketapi.cpp
index b66fced..456511d 100644
--- a/src/gui/socketapi.cpp
+++ b/src/gui/socketapi.cpp
@@ -534,9 +534,7 @@ SyncFileStatus SocketApi::fileStatus(Folder *folder, const QString& systemFileNa
         fileNameSlash += QLatin1Char('/');
     }
 
-    QFileInfo fi(file);
-
-    if( !FileSystem::fileExists(fi) ) {
+    if( !FileSystem::fileExists(file) ) {
         qDebug() << "OO File " << file << " is not existing";
         return SyncFileStatus(SyncFileStatus::STATUS_STAT_ERROR);
     }
@@ -544,6 +542,7 @@ 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 19d1c77..5e014f7 100644
--- a/src/libsync/filesystem.cpp
+++ b/src/libsync/filesystem.cpp
@@ -251,17 +251,6 @@ qint64 FileSystem::getSize(const QString& filename)
     return QFileInfo(filename).size();
 }
 
-qint64 FileSystem::getSize(const QFileInfo& fi)
-{
-#ifdef Q_OS_WIN
-    if (isLnkFile(fi)) {
-        // Use csync to get the file size. Qt seems unable to get at it.
-        return getSizeWithCsync(fi.absoluteFilePath());
-    }
-#endif
-    return fi.size();
-}
-
 #ifdef Q_OS_WIN
 static bool fileExistsWin(const QString& filename)
 {
@@ -288,17 +277,6 @@ bool FileSystem::fileExists(const QString& filename)
     return file.exists();
 }
 
-bool FileSystem::fileExists(const QFileInfo& fi)
-{
-#ifdef Q_OS_WIN
-    if (isLnkFile(fi)) {
-        // Use a native check.
-        return fileExistsWin(fi.absoluteFilePath());
-    }
-#endif
-    return fi.exists();
-}
-
 #ifdef Q_OS_WIN
 QString FileSystem::fileSystemForPath(const QString & path)
 {
diff --git a/src/libsync/filesystem.h b/src/libsync/filesystem.h
index ec72e48..ea97a86 100644
--- a/src/libsync/filesystem.h
+++ b/src/libsync/filesystem.h
@@ -51,7 +51,6 @@ bool setModTime(const QString &filename, time_t modTime);
  * See https://bugreports.qt.io/browse/QTBUG-24831.
  */
 qint64 OWNCLOUDSYNC_EXPORT getSize(const QString& filename);
-qint64 OWNCLOUDSYNC_EXPORT getSize(const QFileInfo& fi);
 
 /** Checks whether a file exists.
  *
@@ -59,7 +58,6 @@ qint64 OWNCLOUDSYNC_EXPORT getSize(const QFileInfo& fi);
  * files, see above.
  */
 bool OWNCLOUDSYNC_EXPORT fileExists(const QString& filename);
-bool OWNCLOUDSYNC_EXPORT fileExists(const QFileInfo& fi);
 
 /**
  * Rename the file \a originFileName to \a destinationFileName, and overwrite the destination if it
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp
index 712f2ca..73a3d2d 100644
--- a/src/libsync/propagatedownload.cpp
+++ b/src/libsync/propagatedownload.cpp
@@ -502,7 +502,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
     }
 
     QFileInfo existingFile(fn);
-    if(FileSystem::fileExists(existingFile) && existingFile.permissions() != _tmpFile.permissions()) {
+    if(FileSystem::fileExists(fn) && existingFile.permissions() != _tmpFile.permissions()) {
         _tmpFile.setPermissions(existingFile.permissions());
     }
 
@@ -531,7 +531,7 @@ void PropagateDownloadFileQNAM::downloadFinished()
     // Maybe we downloaded a newer version of the file than we thought we would...
     // Get up to date information for the journal.
     FileSystem::setModTime(fn, _item._modtime);
-    _item._size = FileSystem::getSize(existingFile);
+    _item._size = FileSystem::getSize(fn);
 
     _propagator->_journal->setFileRecord(SyncJournalFileRecord(_item, fn));
     _propagator->_journal->setDownloadInfo(_item._file, SyncJournalDb::DownloadInfo());
diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp
index 848e538..faf0a8b 100644
--- a/src/libsync/propagateupload.cpp
+++ b/src/libsync/propagateupload.cpp
@@ -155,18 +155,20 @@ bool PollJob::finished()
 
 void PropagateUploadFileQNAM::start()
 {
-    if (_propagator->_abortRequested.fetchAndAddRelaxed(0))
+    if (_propagator->_abortRequested.fetchAndAddRelaxed(0)) {
         return;
+    }
 
-    QFileInfo fi(_propagator->getFilePath(_item._file));
-    if (!FileSystem::fileExists(fi)) {
+    const QString fullFilePath(_propagator->getFilePath(_item._file));
+
+    if (!FileSystem::fileExists(fullFilePath)) {
         done(SyncFileItem::SoftError, tr("File Removed"));
         return;
     }
 
     // Update the mtime and size, it might have changed since discovery.
-    _item._modtime = FileSystem::getModTime(fi.absoluteFilePath());
-    quint64 fileSize = FileSystem::getSize(fi);
+    _item._modtime = FileSystem::getModTime(fullFilePath);
+    quint64 fileSize = FileSystem::getSize(fullFilePath);
     _item._size = fileSize;
 
     // But skip the file if the mtime is too close to 'now'!
@@ -515,11 +517,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
     bool finished = job->reply()->hasRawHeader("ETag")
             || job->reply()->hasRawHeader("OC-ETag");
 
-
-    QFileInfo fi(_propagator->getFilePath(_item._file));
-
     // Check if the file still exists
-    if( !FileSystem::fileExists(fi) ) {
+    const QString fullFilePath(_propagator->getFilePath(_item._file));
+    if( !FileSystem::fileExists(fullFilePath) ) {
         if (!finished) {
             abortWithError(SyncFileItem::SoftError, tr("The local file was removed during sync."));
             return;
@@ -529,8 +529,9 @@ void PropagateUploadFileQNAM::slotPutFinished()
     }
 
     // compare expected and real modification time of the file and size
-    const time_t new_mtime = FileSystem::getModTime(fi.absoluteFilePath());
-    const quint64 new_size = static_cast<quint64>(FileSystem::getSize(fi));
+    const time_t new_mtime = FileSystem::getModTime(fullFilePath);
+    const quint64 new_size = static_cast<quint64>(FileSystem::getSize(fullFilePath));
+    QFileInfo fi(_propagator->getFilePath(_item._file));
     if (new_mtime != _item._modtime || new_size != _item._size) {
         qDebug() << "The local file has changed during upload:"
                  << "mtime: " << _item._modtime << "<->" << new_mtime
diff --git a/src/libsync/propagatorjobs.cpp b/src/libsync/propagatorjobs.cpp
index 38c536a..8c00d28 100644
--- a/src/libsync/propagatorjobs.cpp
+++ b/src/libsync/propagatorjobs.cpp
@@ -96,7 +96,7 @@ void PropagateLocalRemove::start()
         }
     } else {
         QFile file(filename);
-        if (FileSystem::fileExists(file) && !file.remove()) {
+        if (FileSystem::fileExists(filename) && !file.remove()) {
             done(SyncFileItem::NormalError, file.errorString());
             return;
         }

-- 
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