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; }