Skip to content

Commit

Permalink
Merge pull request #7208 from nextcloud/bugfix/missingUnlockCommand
Browse files Browse the repository at this point in the history
Bugfix/missing unlock command
  • Loading branch information
mgallien authored Sep 26, 2024
2 parents 1defd32 + c775620 commit 42c89bd
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
7 changes: 4 additions & 3 deletions src/gui/socketapi/socketapi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1110,8 +1110,9 @@ void SocketApi::setFileLock(const QString &localFile, const SyncFileItem::LockSt
}

const auto record = fileData.journalRecord();
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!";

if (lockState == SyncFileItem::LockStatus::UnlockedItem &&
!shareFolder->accountState()->account()->fileCanBeUnlocked(shareFolder->journalDb(), fileData.folderRelativePath)) {
return;
}

Expand All @@ -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<SyncFileItem::LockOwnerType>(record._lockstate._lockOwnerType) : SyncFileItem::LockOwnerType::UserLock);

shareFolder->journalDb()->schedulePathForRemoteDiscovery(fileData.serverRelativePath);
shareFolder->scheduleThisFolderSoon();
Expand Down
13 changes: 11 additions & 2 deletions src/libsync/account.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1022,11 +1022,20 @@ bool Account::fileCanBeUnlocked(SyncJournalDb * const journal,
{
SyncJournalFileRecord record;
if (journal->getFileRecord(folderRelativePath, &record)) {
if (record._lockstate._lockOwnerType != static_cast<int>(SyncFileItem::LockOwnerType::UserLock)) {
if (record._lockstate._lockOwnerType == static_cast<int>(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<int>(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<int>(SyncFileItem::LockOwnerType::TokenLock) &&
record._lockstate._lockToken.isEmpty()) {
qCDebug(lcAccount()) << folderRelativePath << "cannot be unlocked: token lock without known token";
return false;
}

Expand Down
3 changes: 2 additions & 1 deletion src/libsync/propagateuploadng.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
}

Expand Down
3 changes: 2 additions & 1 deletion src/libsync/propagateuploadv1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 + "> (<opaquelocktoken:" + _item->_lockToken.toUtf8() + ">)").toUtf8();
}

Expand Down

0 comments on commit 42c89bd

Please sign in to comment.