mirror of
https://github.com/nextcloud/desktop.git
synced 2024-12-14 01:34:22 +03:00
[CSE] Try to lock repeteadly the folder if needed.
The upload is made in an event loop with more than one upload at the same time, this confuses the hell out of the folder locking mechanism. We need to lock the folder and ask the other trials to try again in a few seconds in the future to give time for the uploader to actually upload the current file that's locking the folder.
This commit is contained in:
parent
9f678652f8
commit
ccd8cff4db
2 changed files with 30 additions and 3 deletions
|
@ -248,12 +248,26 @@ void PropagateUploadFileCommon::slotFolderEncryptedStatusFetched(const QMap<QStr
|
|||
}
|
||||
}
|
||||
|
||||
/* We try to lock a folder, if it's locked we try again in one second.
|
||||
* if it's still locked we try again in one second. looping untill one minute.
|
||||
* -> fail.
|
||||
* the 'loop': /
|
||||
* slotFolderEncryptedIdReceived -> slotTryLock -> lockError -> stillTime? -> slotTryLock
|
||||
* \
|
||||
* -> success.
|
||||
*/
|
||||
|
||||
void PropagateUploadFileCommon::slotFolderEncryptedIdReceived(const QStringList &list)
|
||||
{
|
||||
// Got the ID, Try to Lock the Folder!.
|
||||
auto job = qobject_cast<LsColJob *>(sender());
|
||||
const auto& folderInfo = job->_folderInfos.value(list.first());
|
||||
auto *lockJob = new LockEncryptFolderApiJob(propagator()->account(), list.first().toLocal8Bit(), this);
|
||||
_folderLockFirstTry.start();
|
||||
slotTryLock(folderInfo.fileId);
|
||||
}
|
||||
|
||||
void PropagateUploadFileCommon::slotTryLock(const QByteArray& fileId)
|
||||
{
|
||||
auto *lockJob = new LockEncryptFolderApiJob(propagator()->account(), fileId, this);
|
||||
connect(lockJob, &LockEncryptFolderApiJob::success, this, &PropagateUploadFileCommon::slotFolderLockedSuccessfully);
|
||||
connect(lockJob, &LockEncryptFolderApiJob::error, this, &PropagateUploadFileCommon::slotFolderLockedError);
|
||||
lockJob->start();
|
||||
|
@ -266,7 +280,16 @@ void PropagateUploadFileCommon::slotFolderLockedSuccessfully(const QByteArray& f
|
|||
|
||||
void PropagateUploadFileCommon::slotFolderLockedError(const QByteArray& fileId, int httpErrorCode)
|
||||
{
|
||||
qDebug() << "Folder" << fileId << "Coundn't be locked.";
|
||||
// Add a counter or Something, this will enter in a loop.
|
||||
QTimer::singleShot(1000, this, [this, fileId]{
|
||||
if (_folderLockFirstTry.elapsed() > /* one minute */ 60000) {
|
||||
qDebug() << "One minute passed, ignoring more attemps to lock the folder.";
|
||||
return;
|
||||
}
|
||||
slotTryLock(fileId);
|
||||
});
|
||||
|
||||
qDebug() << "Folder" << fileId << "Coundn't be locked.";
|
||||
}
|
||||
|
||||
void PropagateUploadFileCommon::slotFolderEncryptedIdError(QNetworkReply *r)
|
||||
|
|
|
@ -285,7 +285,11 @@ private slots:
|
|||
void slotFolderEncryptedIdError(QNetworkReply *r);
|
||||
void slotFolderLockedSuccessfully(const QByteArray& fileId, const QByteArray& token);
|
||||
void slotFolderLockedError(const QByteArray& fileId, int httpErrorCode);
|
||||
void slotTryLock(const QByteArray& fileId);
|
||||
|
||||
// Private Encryption Stuff
|
||||
private:
|
||||
QElapsedTimer _folderLockFirstTry;
|
||||
|
||||
protected:
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue