[Pkg-owncloud-commits] [owncloud-client] 71/219: Propagator: Use csync to get the modification time.

Sandro Knauß hefee-guest at moszumanska.debian.org
Sat Oct 11 14:43:11 UTC 2014


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 2630a73a1c0a8dd0ca0888a35f290f08407cb039
Author: Christian Kamm <kamm at incasoftware.de>
Date:   Thu Sep 4 11:20:41 2014 +0200

    Propagator: Use csync to get the modification time.
    
    See owncloud/core#9781
---
 src/mirall/filesystem.cpp      | 29 ++++++++++++++++++++++++++++-
 src/mirall/filesystem.h        |  8 ++++++++
 src/mirall/propagator_qnam.cpp |  6 ++++--
 src/mirall/socketapi.cpp       |  3 ++-
 4 files changed, 42 insertions(+), 4 deletions(-)

diff --git a/src/mirall/filesystem.cpp b/src/mirall/filesystem.cpp
index b317b32..7c9e000 100644
--- a/src/mirall/filesystem.cpp
+++ b/src/mirall/filesystem.cpp
@@ -12,7 +12,10 @@
  */
 
 #include "filesystem.h"
+
+#include "utility.h"
 #include <QFile>
+#include <QFileInfo>
 #include <QDebug>
 
 #if QT_VERSION < QT_VERSION_CHECK(5, 0, 0)
@@ -24,11 +27,16 @@
 #include <winbase.h>
 #endif
 
-
 // We use some internals of csync:
 extern "C" int c_utimes(const char *, const struct timeval *);
 extern "C" void csync_win32_set_file_hidden( const char *file, bool h );
 
+extern "C" {
+#include "vio/csync_vio_handle.h"
+#include "vio/csync_vio_file_stat.h"
+#include "vio/csync_vio_local.h"
+}
+
 namespace Mirall {
 
 bool FileSystem::fileEquals(const QString& fn1, const QString& fn2)
@@ -69,6 +77,25 @@ void FileSystem::setFileHidden(const QString& filename, bool hidden)
     return csync_win32_set_file_hidden(filename.toUtf8().constData(), hidden);
 }
 
+time_t FileSystem::getModTime(const QString &filename)
+{
+    csync_vio_file_stat_t* stat = csync_vio_file_stat_new();
+    qint64 result = -1;
+    if (csync_vio_local_stat(filename.toUtf8().data(), stat) != -1
+            && (stat->fields & CSYNC_VIO_FILE_STAT_FIELDS_MTIME))
+    {
+        result = stat->mtime;
+    }
+    else
+    {
+        qDebug() << "Could not get modification time for" << filename
+                 << "with csync, using QFileInfo";
+        result = Utility::qDateTimeToTime_t(QFileInfo(filename).lastModified());
+    }
+    csync_vio_file_stat_destroy(stat);
+    return result;
+}
+
 void FileSystem::setModTime(const QString& filename, time_t modTime)
 {
     struct timeval times[2];
diff --git a/src/mirall/filesystem.h b/src/mirall/filesystem.h
index c8e10ce..27fe965 100644
--- a/src/mirall/filesystem.h
+++ b/src/mirall/filesystem.h
@@ -32,6 +32,14 @@ bool fileEquals(const QString &fn1, const QString &fn2);
 /** Mark the file as hidden  (only has effects on windows) */
 void OWNCLOUDSYNC_EXPORT setFileHidden(const QString& filename, bool hidden);
 
+
+/** Get the mtime for a filepath.
+ *
+ * Use this over QFileInfo::lastModified() to avoid timezone related bugs. See
+ * owncloud/core#9781 for details.
+ */
+time_t getModTime(const QString &filename);
+
 void setModTime(const QString &filename, time_t modTime);
 
 /**
diff --git a/src/mirall/propagator_qnam.cpp b/src/mirall/propagator_qnam.cpp
index 022d585..0dd148d 100644
--- a/src/mirall/propagator_qnam.cpp
+++ b/src/mirall/propagator_qnam.cpp
@@ -314,8 +314,10 @@ void PropagateUploadFileQNAM::slotPutFinished()
             return;
         }
 
-        if (Utility::qDateTimeToTime_t(fi.lastModified()) != _item._modtime) {
-            qDebug() << "The local file has changed during upload:" << _item._modtime << "!=" << Utility::qDateTimeToTime_t(fi.lastModified())  << fi.lastModified();
+        const time_t new_mtime = FileSystem::getModTime(fi.absoluteFilePath());
+        if (new_mtime != _item._modtime) {
+            qDebug() << "The local file has changed during upload:" << _item._modtime << "!=" << new_mtime
+                     << ", QFileInfo: " << Utility::qDateTimeToTime_t(fi.lastModified()) << fi.lastModified();
             _propagator->_activeJobs--;
             done(SyncFileItem::SoftError, tr("Local file changed during sync."));
             // FIXME:  the legacy code was retrying for a few seconds.
diff --git a/src/mirall/socketapi.cpp b/src/mirall/socketapi.cpp
index 0d7b7ea..bb86ae6 100644
--- a/src/mirall/socketapi.cpp
+++ b/src/mirall/socketapi.cpp
@@ -22,6 +22,7 @@
 #include "mirall/theme.h"
 #include "mirall/syncjournalfilerecord.h"
 #include "mirall/syncfileitem.h"
+#include "mirall/filesystem.h"
 #include "version.h"
 
 #include <QDebug>
@@ -165,7 +166,7 @@ SyncFileStatus fileStatus(Folder *folder, const QString& systemFileName, c_strli
     if( type == CSYNC_FTW_TYPE_DIR ) {
         // compute recursive status of the directory
         status = recursiveFolderStatus( folder, fileName, excludes );
-    } else if(fi.lastModified() != rec._modtime ) {
+    } else if( FileSystem::getModTime(fi.absoluteFilePath()) != Utility::qDateTimeToTime_t(rec._modtime) ) {
         // file was locally modified.
         status.set(SyncFileStatus::STATUS_EVAL);
     } else {

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