From 16926c00d520764d41da02e803d47d4ce52b7435 Mon Sep 17 00:00:00 2001 From: alex-z Date: Fri, 12 Jan 2024 19:14:53 +0100 Subject: [PATCH] Use different lock types. Signed-off-by: alex-z --- src/gui/editlocallyjob.cpp | 2 +- src/gui/folder.cpp | 4 ++-- src/gui/socketapi/socketapi.cpp | 4 +--- src/libsync/lockfilejobs.cpp | 8 ++++---- src/libsync/syncfileitem.h | 3 +-- 5 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/gui/editlocallyjob.cpp b/src/gui/editlocallyjob.cpp index f373a98addfe5..d20a9bb699c57 100644 --- a/src/gui/editlocallyjob.cpp +++ b/src/gui/editlocallyjob.cpp @@ -651,7 +651,7 @@ void EditLocallyJob::lockFile() _folderForFile->path(), _folderForFile->journalDb(), SyncFileItem::LockStatus::LockedItem, - SyncFileItem::LockOwnerType::AppLock); + SyncFileItem::LockOwnerType::TokenLock); } void EditLocallyJob::disconnectFolderSignals() diff --git a/src/gui/folder.cpp b/src/gui/folder.cpp index bf9e49b36e9ff..d5e03e76a12b6 100644 --- a/src/gui/folder.cpp +++ b/src/gui/folder.cpp @@ -649,7 +649,7 @@ void Folder::slotFilesLockReleased(const QSet &files) } const auto canUnlockFile = isFileRecordValid && rec._lockstate._locked - && rec._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::AppLock) + && rec._lockstate._lockOwnerType == static_cast(SyncFileItem::LockOwnerType::TokenLock) && rec._lockstate._lockOwnerId == _accountState->account()->davUser(); if (!canUnlockFile) { @@ -721,7 +721,7 @@ void Folder::slotLockedFilesFound(const QSet &files) path(), journalDb(), SyncFileItem::LockStatus::LockedItem, - SyncFileItem::LockOwnerType::AppLock); + SyncFileItem::LockOwnerType::TokenLock); } } diff --git a/src/gui/socketapi/socketapi.cpp b/src/gui/socketapi/socketapi.cpp index 7d5c34fed1e56..1df11cf555080 100644 --- a/src/gui/socketapi/socketapi.cpp +++ b/src/gui/socketapi/socketapi.cpp @@ -1092,9 +1092,7 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt } const auto record = fileData.journalRecord(); - const auto canAffectLockState = static_cast(record._lockstate._lockOwnerType) == SyncFileItem::LockOwnerType::NoLock - || static_cast(record._lockstate._lockOwnerType) == SyncFileItem::LockOwnerType::UserLock; - if (!canAffectLockState) { + if (static_cast(record._lockstate._lockOwnerType) != SyncFileItem::LockOwnerType::UserLock) { qCDebug(lcSocketApi) << "Only user lock state or non-locked files can be affected manually!"; return; } diff --git a/src/libsync/lockfilejobs.cpp b/src/libsync/lockfilejobs.cpp index b38dbe8e504d6..972bffa39a202 100644 --- a/src/libsync/lockfilejobs.cpp +++ b/src/libsync/lockfilejobs.cpp @@ -52,9 +52,9 @@ void LockFileJob::start() QNetworkRequest request; request.setRawHeader(QByteArrayLiteral("X-User-Lock"), QByteArrayLiteral("1")); if (_account->capabilities().filesLockTypeAvailable()) { - if (_requestedLockOwnerType == SyncFileItem::LockOwnerType::AppLock) { - request.setRawHeader(QByteArrayLiteral("X-User-Lock-Type"), ("1")); - } else if (_requestedLockOwnerType == SyncFileItem::LockOwnerType::UserLock) { + if (_requestedLockOwnerType == SyncFileItem::LockOwnerType::UserLock) { + request.setRawHeader(QByteArrayLiteral("X-User-Lock-Type"), ("0")); + } else if (_requestedLockOwnerType == SyncFileItem::LockOwnerType::TokenLock) { request.setRawHeader(QByteArrayLiteral("X-User-Lock-Type"), ("2")); } } @@ -215,7 +215,7 @@ void LockFileJob::decodeStartElement(const QString &name, if (isValid) { _lockOwnerType = static_cast(convertedValue); } else { - _lockOwnerType = SyncFileItem::LockOwnerType::NoLock; + _lockOwnerType = SyncFileItem::LockOwnerType::UserLock; } } else if (name == QStringLiteral("lock-owner-displayname")) { _userDisplayName = reader.readElementText(); diff --git a/src/libsync/syncfileitem.h b/src/libsync/syncfileitem.h index e00c17f19d67c..a7dbcbd340f4e 100644 --- a/src/libsync/syncfileitem.h +++ b/src/libsync/syncfileitem.h @@ -115,9 +115,8 @@ class OWNCLOUDSYNC_EXPORT SyncFileItem Q_ENUM(LockStatus) enum class LockOwnerType : int{ - NoLock = 0, + UserLock = 0, AppLock = 1, - UserLock = 2, TokenLock = 3, };