From c37792f58fd396a8cd5e66d7249314ed40dba558 Mon Sep 17 00:00:00 2001 From: Christian Kamm Date: Thu, 26 Feb 2015 11:00:06 +0100 Subject: [PATCH] Propagator: Upload files with future timestamps. #2880 --- src/gui/folderman.cpp | 5 +++-- src/libsync/propagateupload.cpp | 26 ++++++++++++++++---------- 2 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/gui/folderman.cpp b/src/gui/folderman.cpp index 853fef2c9..f401020b1 100644 --- a/src/gui/folderman.cpp +++ b/src/gui/folderman.cpp @@ -43,8 +43,9 @@ FolderMan* FolderMan::_instance = 0; * The minimum time between a sync being requested and it * being executed in milliseconds. * - * This delay must be larger than the minFileAgeForUpload in - * the propagator. + * This delay must be large enough to ensure fileIsStillChanging() + * in the upload propagator doesn't decide to skip the file because + * the modification was too recent. */ static qint64 msBetweenRequestAndSync = 2000; diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index f3a6c0dc2..c3f50f3a5 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -31,16 +31,23 @@ namespace OCC { /** - * The mtime of a file must be at least this many milliseconds in - * the past for an upload to be started. Otherwise the propagator will - * assume it's still being changed and skip it. + * We do not want to upload files that are currently being modified. + * To avoid that, we don't upload files that have a modification time + * that is too close to the current time. * - * This value must be smaller than the msBetweenRequestAndSync in - * the folder manager. - * - * Two seconds has shown to be a good value in tests. + * This interacts with the msBetweenRequestAndSync delay in the folder + * manager. If that delay between file-change notification and sync + * has passed, we should accept the file for upload here. */ -static int minFileAgeForUpload = 2000; +static bool fileIsStillChanging(const SyncFileItem & item) +{ + const QDateTime modtime = Utility::qDateTimeFromTime_t(item._modtime); + const qint64 msSinceMod = modtime.msecsTo(QDateTime::currentDateTime()); + + return msSinceMod < 2000 + // if the mtime is too much in the future we *do* upload the file + && msSinceMod > -10000; +} static qint64 chunkSize() { static uint chunkSize; @@ -165,8 +172,7 @@ void PropagateUploadFileQNAM::start() // But skip the file if the mtime is too close to 'now'! // That usually indicates a file that is still being changed // or not yet fully copied to the destination. - QDateTime modtime = Utility::qDateTimeFromTime_t(_item._modtime); - if (modtime.msecsTo(QDateTime::currentDateTime()) < minFileAgeForUpload) { + if (fileIsStillChanging(_item)) { _propagator->_anotherSyncNeeded = true; done(SyncFileItem::SoftError, tr("Local file changed during sync.")); return;