Skip to content

Commit

Permalink
Use different lock types.
Browse files Browse the repository at this point in the history
Signed-off-by: alex-z <[email protected]>
  • Loading branch information
allexzander committed Jan 18, 2024
1 parent 9131ef2 commit 16926c0
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/gui/editlocallyjob.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -651,7 +651,7 @@ void EditLocallyJob::lockFile()
_folderForFile->path(),
_folderForFile->journalDb(),
SyncFileItem::LockStatus::LockedItem,
SyncFileItem::LockOwnerType::AppLock);
SyncFileItem::LockOwnerType::TokenLock);
}

void EditLocallyJob::disconnectFolderSignals()
Expand Down
4 changes: 2 additions & 2 deletions src/gui/folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ void Folder::slotFilesLockReleased(const QSet<QString> &files)
}
const auto canUnlockFile = isFileRecordValid
&& rec._lockstate._locked
&& rec._lockstate._lockOwnerType == static_cast<qint64>(SyncFileItem::LockOwnerType::AppLock)
&& rec._lockstate._lockOwnerType == static_cast<qint64>(SyncFileItem::LockOwnerType::TokenLock)
&& rec._lockstate._lockOwnerId == _accountState->account()->davUser();

if (!canUnlockFile) {
Expand Down Expand Up @@ -721,7 +721,7 @@ void Folder::slotLockedFilesFound(const QSet<QString> &files)
path(),
journalDb(),
SyncFileItem::LockStatus::LockedItem,
SyncFileItem::LockOwnerType::AppLock);
SyncFileItem::LockOwnerType::TokenLock);
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1092,9 +1092,7 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt
}

const auto record = fileData.journalRecord();
const auto canAffectLockState = static_cast<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) == SyncFileItem::LockOwnerType::NoLock
|| static_cast<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) == SyncFileItem::LockOwnerType::UserLock;
if (!canAffectLockState) {
if (static_cast<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) != SyncFileItem::LockOwnerType::UserLock) {
qCDebug(lcSocketApi) << "Only user lock state or non-locked files can be affected manually!";
return;
}
Expand Down
8 changes: 4 additions & 4 deletions src/libsync/lockfilejobs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"));
}
}
Expand Down Expand Up @@ -215,7 +215,7 @@ void LockFileJob::decodeStartElement(const QString &name,
if (isValid) {
_lockOwnerType = static_cast<SyncFileItem::LockOwnerType>(convertedValue);
} else {
_lockOwnerType = SyncFileItem::LockOwnerType::NoLock;
_lockOwnerType = SyncFileItem::LockOwnerType::UserLock;
}
} else if (name == QStringLiteral("lock-owner-displayname")) {
_userDisplayName = reader.readElementText();
Expand Down
3 changes: 1 addition & 2 deletions src/libsync/syncfileitem.h
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};

Expand Down

0 comments on commit 16926c0

Please sign in to comment.