diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 81d980405..bd68063fa 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1110,8 +1110,9 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt } const auto record = fileData.journalRecord(); - if (static_cast(record._lockstate._lockOwnerType) != SyncFileItem::LockOwnerType::UserLock) { - qCDebug(lcSocketApi) << "Only user lock state or non-locked files can be affected manually!"; + + if (lockState == SyncFileItem::LockStatus::UnlockedItem && + !shareFolder->accountState()->account()->fileCanBeUnlocked(shareFolder->journalDb(), fileData.folderRelativePath)) { return; } @@ -1120,7 +1121,7 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt shareFolder->path(), shareFolder->journalDb(), lockState, - SyncFileItem::LockOwnerType::UserLock); + (lockState == SyncFileItem::LockStatus::UnlockedItem) ? static_cast(record._lockstate._lockOwnerType) : SyncFileItem::LockOwnerType::UserLock); shareFolder->journalDb()->schedulePathForRemoteDiscovery(fileData.serverRelativePath); shareFolder->scheduleThisFolderSoon(); diff --git a/src/libsync/account.cpp b/src/libsync/account.cpp index 74b1856f4..401e22ae9 100644 --- a/src/libsync/account.cpp +++ b/src/libsync/account.cpp @@ -1022,11 +1022,20 @@ bool Account::fileCanBeUnlocked(SyncJournalDb * const journal, { SyncJournalFileRecord record; if (journal->getFileRecord(folderRelativePath, &record)) { - if (record._lockstate._lockOwnerType != static_cast(SyncFileItem::LockOwnerType::UserLock)) { + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::AppLock)) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: app lock"; return false; } - if (record._lockstate._lockOwnerId != sharedFromThis()->davUser()) { + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::UserLock) && + record._lockstate._lockOwnerId != sharedFromThis()->davUser()) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: user lock from" << record._lockstate._lockOwnerId; + return false; + } + + if (record._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::TokenLock) && + record._lockstate._lockToken.isEmpty()) { + qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: token lock without known token"; return false; } diff --git a/src/libsync/propagateuploadng.cpp b/src/libsync/propagateuploadng.cpp index a67225d2a..32e1192f3 100644 --- a/src/libsync/propagateuploadng.cpp +++ b/src/libsync/propagateuploadng.cpp @@ -328,7 +328,8 @@ void PropagateUploadFileNG::finishUpload() const auto fileSize = _fileToUpload._size; headers[QByteArrayLiteral("OC-Total-Length")] = QByteArray::number(fileSize); - if (_item->_locked == SyncFileItem::LockStatus::LockedItem) { + if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock && + _item->_locked == SyncFileItem::LockStatus::LockedItem) { headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (_lockToken.toUtf8() + ">)").toUtf8(); } diff --git a/src/libsync/propagateuploadv1.cpp b/src/libsync/propagateuploadv1.cpp index 7467b2ce3..6bab06305 100644 --- a/src/libsync/propagateuploadv1.cpp +++ b/src/libsync/propagateuploadv1.cpp @@ -102,7 +102,8 @@ void PropagateUploadFileV1::startNextChunk() QString path = _fileToUpload._file; - if (_item->_locked == SyncFileItem::LockStatus::LockedItem) { + if (_item->_lockOwnerType == SyncFileItem::LockOwnerType::TokenLock && + _item->_locked == SyncFileItem::LockStatus::LockedItem) { headers[QByteArrayLiteral("If")] = (QLatin1String("<") + propagator()->account()->davUrl().toString() + _fileToUpload._file + "> (_lockToken.toUtf8() + ">)").toUtf8(); }