do not get stuck forever in sync in case of errors
authorMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 10 Dec 2021 09:39:33 +0000 (10:39 +0100)
committerMatthieu Gallien <matthieu.gallien@nextcloud.com>
Fri, 10 Dec 2021 10:28:35 +0000 (11:28 +0100)
when a local file has invalid date and we try to upload it, properly
handle the error such that we are not stuck forever in sync state

Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
src/libsync/bulkpropagatorjob.cpp
src/libsync/propagateupload.cpp

index 9650bfa187329eb80225db762381a27fec2d69a5..b659b293d548ac65d276dedd199180b32ce1a16a 100644 (file)
@@ -276,10 +276,12 @@ void BulkPropagatorJob::slotStartUpload(SyncFileItemPtr item,
 
     item->_modtime = FileSystem::getModTime(originalFilePath);
     if (item->_modtime <= 0) {
-        return slotOnErrorStartFolderUnlock(item, SyncFileItem::SoftError, tr("Local file has invalid modified time. Do not upload to the server."));
+        _pendingChecksumFiles.remove(item->_file);
+        return slotOnErrorStartFolderUnlock(item, SyncFileItem::NormalError, tr("File %1 has invalid modified time. Do not upload to the server.").arg(QDir::toNativeSeparators(item->_file)));
     }
     if (prevModtime != item->_modtime) {
         propagator()->_anotherSyncNeeded = true;
+        _pendingChecksumFiles.remove(item->_file);
         qDebug() << "trigger another sync after checking modified time of item" << item->_file << "prevModtime" << prevModtime << "Curr" << item->_modtime;
         return slotOnErrorStartFolderUnlock(item, SyncFileItem::SoftError, tr("Local file changed during syncing. It will be resumed."));
     }
@@ -292,6 +294,7 @@ void BulkPropagatorJob::slotStartUpload(SyncFileItemPtr item,
     // or not yet fully copied to the destination.
     if (fileIsStillChanging(*item)) {
         propagator()->_anotherSyncNeeded = true;
+        _pendingChecksumFiles.remove(item->_file);
         return slotOnErrorStartFolderUnlock(item, SyncFileItem::SoftError, tr("Local file changed during sync."));
     }
 
index c18fe7069b5a629a4ddc02fc348cbfe564fa07b7..b655cfdfb545a276d024b40e84cb1b032e97e530 100644 (file)
@@ -316,9 +316,9 @@ void PropagateUploadFileCommon::slotComputeContentChecksum()
     // and not the _fileToUpload because we are checking the original file, not there
     // probably temporary one.
     _item->_modtime = FileSystem::getModTime(filePath);
-    Q_ASSERT(_item->_modtime > 0);
     if (_item->_modtime <= 0) {
-        qCWarning(lcPropagateUpload()) << "invalid modified time" << _item->_file << _item->_modtime;
+        slotOnErrorStartFolderUnlock(SyncFileItem::NormalError, tr("File %1 has invalid modified time. Do not upload to the server.").arg(QDir::toNativeSeparators(_item->_file)));
+        return;
     }
 
     const QByteArray checksumType = propagator()->account()->capabilities().preferredUploadChecksumType();
@@ -392,8 +392,8 @@ void PropagateUploadFileCommon::slotStartUpload(const QByteArray &transmissionCh
         return slotOnErrorStartFolderUnlock(SyncFileItem::SoftError, tr("File Removed (start upload) %1").arg(fullFilePath));
     }
     if (_item->_modtime <= 0) {
-        return slotOnErrorStartFolderUnlock(
-            SyncFileItem::SoftError, tr("Local file has invalid modified time. Do not upload to the server."));
+        slotOnErrorStartFolderUnlock(SyncFileItem::NormalError, tr("File %1 has invalid modified time. Do not upload to the server.").arg(QDir::toNativeSeparators(_item->_file)));
+        return;
     }
     Q_ASSERT(_item->_modtime > 0);
     if (_item->_modtime <= 0) {
@@ -405,8 +405,8 @@ void PropagateUploadFileCommon::slotStartUpload(const QByteArray &transmissionCh
 
     _item->_modtime = FileSystem::getModTime(originalFilePath);
     if (_item->_modtime <= 0) {
-        return slotOnErrorStartFolderUnlock(
-            SyncFileItem::SoftError, tr("Local file has invalid modified time. Do not upload to the server."));
+        slotOnErrorStartFolderUnlock(SyncFileItem::NormalError, tr("File %1 has invalid modified time. Do not upload to the server.").arg(QDir::toNativeSeparators(_item->_file)));
+        return;
     }
     Q_ASSERT(_item->_modtime > 0);
     if (_item->_modtime <= 0) {