diff options
author | Matthieu Gallien <matthieu.gallien@nextcloud.com> | 2021-12-06 17:07:57 +0300 |
---|---|---|
committer | Matthieu Gallien (Rebase PR Action) <matthieu_gallien@yahoo.fr> | 2021-12-08 10:22:24 +0300 |
commit | 9523c036d680931f3730cfae42219a6502fa606e (patch) | |
tree | 4ac79dae1e865ede0b637b4822138ca57714c4b6 /src/libsync | |
parent | 2223c6e49865d5e96819d5cc136b1012211dbc50 (diff) |
assert on invalid modtime
Signed-off-by: Matthieu Gallien <matthieu.gallien@nextcloud.com>
Diffstat (limited to 'src/libsync')
-rw-r--r-- | src/libsync/propagatedownload.cpp | 7 | ||||
-rw-r--r-- | src/libsync/propagateupload.cpp | 6 | ||||
-rw-r--r-- | src/libsync/propagateuploadng.cpp | 4 | ||||
-rw-r--r-- | src/libsync/propagateuploadv1.cpp | 5 |
4 files changed, 22 insertions, 0 deletions
diff --git a/src/libsync/propagatedownload.cpp b/src/libsync/propagatedownload.cpp index 10ccd97db..7b17c364c 100644 --- a/src/libsync/propagatedownload.cpp +++ b/src/libsync/propagatedownload.cpp @@ -564,6 +564,7 @@ void PropagateDownloadFile::startAfterIsEncryptedIsChecked() return checksum_header.startsWith("SHA") || checksum_header.startsWith("MD5:"); }; + Q_ASSERT(_item->_modtime > 0); if (_item->_instruction == CSYNC_INSTRUCTION_CONFLICT && _item->_size == _item->_previousSize && !_item->_checksumHeader.isEmpty() @@ -592,11 +593,14 @@ void PropagateDownloadFile::conflictChecksumComputed(const QByteArray &checksumT // Apply the server mtime locally if necessary, ensuring the journal // and local mtimes end up identical auto fn = propagator()->fullLocalPath(_item->_file); + Q_ASSERT(_item->_modtime > 0); if (_item->_modtime != _item->_previousModtime) { + Q_ASSERT(_item->_modtime > 0); FileSystem::setModTime(fn, _item->_modtime); emit propagator()->touchedFile(fn); } _item->_modtime = FileSystem::getModTime(fn); + Q_ASSERT(_item->_modtime > 0); updateMetadata(/*isConflict=*/false); return; } @@ -820,6 +824,7 @@ void PropagateDownloadFile::slotGetFinished() // It is possible that the file was modified on the server since we did the discovery phase // so make sure we have the up-to-date time _item->_modtime = job->lastModified(); + Q_ASSERT(_item->_modtime > 0); } _tmpFile.close(); @@ -1058,10 +1063,12 @@ void PropagateDownloadFile::downloadFinished() return; } + Q_ASSERT(_item->_modtime > 0); FileSystem::setModTime(_tmpFile.fileName(), _item->_modtime); // We need to fetch the time again because some file systems such as FAT have worse than a second // Accuracy, and we really need the time from the file system. (#3103) _item->_modtime = FileSystem::getModTime(_tmpFile.fileName()); + Q_ASSERT(_item->_modtime > 0); bool previousFileExists = FileSystem::fileExists(fn); if (previousFileExists) { diff --git a/src/libsync/propagateupload.cpp b/src/libsync/propagateupload.cpp index 0ec9116e4..e74c49c90 100644 --- a/src/libsync/propagateupload.cpp +++ b/src/libsync/propagateupload.cpp @@ -210,6 +210,7 @@ void PropagateUploadFileCommon::start() } _item->_file = _item->_renameTarget; _item->_modtime = FileSystem::getModTime(newFilePathAbsolute); + Q_ASSERT(_item->_modtime > 0); } SyncJournalFileRecord parentRec; @@ -312,6 +313,7 @@ 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); const QByteArray checksumType = propagator()->account()->capabilities().preferredUploadChecksumType(); @@ -383,11 +385,13 @@ void PropagateUploadFileCommon::slotStartUpload(const QByteArray &transmissionCh if (!FileSystem::fileExists(fullFilePath)) { return slotOnErrorStartFolderUnlock(SyncFileItem::SoftError, tr("File Removed (start upload) %1").arg(fullFilePath)); } + Q_ASSERT(_item->_modtime > 0); time_t prevModtime = _item->_modtime; // the _item value was set in PropagateUploadFile::start() // but a potential checksum calculation could have taken some time during which the file could // have been changed again, so better check again here. _item->_modtime = FileSystem::getModTime(originalFilePath); + Q_ASSERT(_item->_modtime > 0); if (prevModtime != _item->_modtime) { propagator()->_anotherSyncNeeded = true; qDebug() << "prevModtime" << prevModtime << "Curr" << _item->_modtime; @@ -585,6 +589,7 @@ void PropagateUploadFileCommon::startPollJob(const QString &path) info._file = _item->_file; info._url = path; info._modtime = _item->_modtime; + Q_ASSERT(_item->_modtime > 0); info._fileSize = _item->_size; propagator()->_journal->setPollInfo(info); propagator()->_journal->commit("add poll info"); @@ -707,6 +712,7 @@ QMap<QByteArray, QByteArray> PropagateUploadFileCommon::headers() { QMap<QByteArray, QByteArray> headers; headers[QByteArrayLiteral("Content-Type")] = QByteArrayLiteral("application/octet-stream"); + Q_ASSERT(_item->_modtime > 0); headers[QByteArrayLiteral("X-OC-Mtime")] = QByteArray::number(qint64(_item->_modtime)); if (qEnvironmentVariableIntValue("OWNCLOUD_LAZYOPS")) headers[QByteArrayLiteral("OC-LazyOps")] = QByteArrayLiteral("true"); diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index 0b4b40a86..674298cbf 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -83,6 +83,7 @@ void PropagateUploadFileNG::doStartUpload() propagator()->_activeJobList.append(this); const SyncJournalDb::UploadInfo progressInfo = propagator()->_journal->getUploadInfo(_item->_file); + Q_ASSERT(_item->_modtime > 0); if (progressInfo._valid && progressInfo.isChunked() && progressInfo._modtime == _item->_modtime && progressInfo._size == _item->_size) { _transferId = progressInfo._transferid; @@ -229,6 +230,7 @@ void PropagateUploadFileNG::slotDeleteJobFinished() void PropagateUploadFileNG::startNewUpload() { ASSERT(propagator()->_activeJobList.count(this) == 1); + Q_ASSERT(_item->_modtime > 0); _transferId = uint(Utility::rand() ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16) ^ qHash(_fileToUpload._file)); _sent = 0; _currentChunk = 0; @@ -238,6 +240,7 @@ void PropagateUploadFileNG::startNewUpload() SyncJournalDb::UploadInfo pi; pi._valid = true; pi._transferid = _transferId; + Q_ASSERT(_item->_modtime > 0); pi._modtime = _item->_modtime; pi._contentChecksum = _item->_checksumHeader; pi._size = _item->_size; @@ -423,6 +426,7 @@ void PropagateUploadFileNG::slotPutFinished() } // Check whether the file changed since discovery - this acts on the original file. + Q_ASSERT(_item->_modtime > 0); if (!FileSystem::verifyFileUnchanged(fullFilePath, _item->_size, _item->_modtime)) { propagator()->_anotherSyncNeeded = true; if (!_finished) { diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index 40662fa20..04683add0 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -39,10 +39,12 @@ void PropagateUploadFileV1::doStartUpload() { _chunkCount = int(std::ceil(_fileToUpload._size / double(chunkSize()))); _startChunk = 0; + Q_ASSERT(_item->_modtime > 0); _transferId = uint(Utility::rand()) ^ uint(_item->_modtime) ^ (uint(_fileToUpload._size) << 16); const SyncJournalDb::UploadInfo progressInfo = propagator()->_journal->getUploadInfo(_item->_file); + Q_ASSERT(_item->_modtime > 0); if (progressInfo._valid && progressInfo.isChunked() && progressInfo._modtime == _item->_modtime && progressInfo._size == _item->_size && (progressInfo._contentChecksum == _item->_checksumHeader || progressInfo._contentChecksum.isEmpty() || _item->_checksumHeader.isEmpty())) { _startChunk = progressInfo._chunk; @@ -56,6 +58,7 @@ void PropagateUploadFileV1::doStartUpload() pi._valid = true; pi._chunk = 0; pi._transferid = 0; // We set a null transfer id because it is not chunked. + Q_ASSERT(_item->_modtime > 0); pi._modtime = _item->_modtime; pi._errorCount = 0; pi._contentChecksum = _item->_checksumHeader; @@ -245,6 +248,7 @@ void PropagateUploadFileV1::slotPutFinished() } // Check whether the file changed since discovery. the file check here is the original and not the temprary. + Q_ASSERT(_item->_modtime > 0); if (!FileSystem::verifyFileUnchanged(fullFilePath, _item->_size, _item->_modtime)) { propagator()->_anotherSyncNeeded = true; if (!_finished) { @@ -283,6 +287,7 @@ void PropagateUploadFileV1::slotPutFinished() } pi._chunk = (currentChunk + _startChunk + 1) % _chunkCount; // next chunk to start with pi._transferid = _transferId; + Q_ASSERT(_item->_modtime > 0); pi._modtime = _item->_modtime; pi._errorCount = 0; // successful chunk upload resets pi._contentChecksum = _item->_checksumHeader; |