Skip to content

fix(editLocally): evaluate lock-record DB call outside Q_ASSERT#9973

Merged
nilsding merged 1 commit into
nextcloud:masterfrom
greatjourney589:fix/editlocally-qassert-side-effect
May 7, 2026
Merged

fix(editLocally): evaluate lock-record DB call outside Q_ASSERT#9973
nilsding merged 1 commit into
nextcloud:masterfrom
greatjourney589:fix/editlocally-qassert-side-effect

Conversation

@greatjourney589
Copy link
Copy Markdown
Contributor

@greatjourney589 greatjourney589 commented May 5, 2026

Resolves

#9972

Summary

In EditLocallyJob::fileAlreadyLocked(), the call that fetches the lock state from
the journal DB was wrapped directly in Q_ASSERT:

Q_ASSERT(_folderForFile->journalDb()->getFileRecord(_relativePathToRemoteRoot, &rec));

Q_ASSERT(x) expands to ((void)0) when QT_NO_DEBUG is defined — i.e. in every
release build the project ships. As a result, getFileRecord() was never called
in release: rec stayed default-constructed, _lockTime and _lockTimeout were both
0, and the user-facing notification read "Lock will last for 0 minutes." every
time someone re-opened an already-locked file via Edit Locally.

The project's own assert header (src/common/asserts.h) explicitly documents that
Q_ASSERT "is only present in debug builds", so this was a misuse of the macro.

Fix

  • Capture the getFileRecord() return value into a local before asserting on it, so
    the DB call always runs.
  • Keep the three Q_ASSERTs for debug-build diagnostics.
  • Add a release-safe fallback: if any precondition fails (record not found, invalid,
    or not actually locked), show a generic notification without the bogus "0 minutes"
    string and return early.

No behavior change in debug builds. In release builds the dialog now shows the real
remaining lock time, matching the fileLockSuccess path.

TODO

  • Fix Q_ASSERT side-effect in EditLocallyJob::fileAlreadyLocked()
  • Add release-safe fallback notification

Checklist

AI (if applicable)

  • The content of this PR was partly or fully generated using AI

Comment thread src/gui/editlocallyjob.cpp Outdated
Comment on lines +522 to +529
if (!recordFetched || !rec.isValid() || !rec._lockstate._locked) {
qCWarning(lcEditLocallyJob()) << "File reported as already locked but journal record is missing or stale, showing notification without remaining time"
<< _relPath << "recordFetched:" << recordFetched << "valid:" << rec.isValid() << "locked:" << rec._lockstate._locked;
fileLockProcedureComplete(tr("File %1 already locked.").arg(_fileName),
tr("You can unlock this file manually once you are finished editing."),
true);
return;
}
Copy link
Copy Markdown
Member

@nilsding nilsding May 7, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How did you manage this notification to show up? while testing the PR I still got the other message:

Image

the only caller of this method (EditLocallyJob::lockFile) already queries the lock state from the sync journal via Account::fileLockStatus
EditLocallyJob::fileAlreadyLocked would then not be called at all in case the file is already unlocked or not present in the sync journal.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is exactly correct. fileAlreadyLocked() is called from within lockFile() only after Account::fileLockStatus() has already executed getFileRecord() on the same journal and confirmed that _locked == true. Therefore, the fallback branch code I had added was, in reality, an unreachable path. I have force-pushed the corrected version. The PR now contains only the minimal fix addressing the Q_ASSERT side effect (+2 −1).

@greatjourney589 greatjourney589 force-pushed the fix/editlocally-qassert-side-effect branch 2 times, most recently from 7b8bbe9 to 3db2948 Compare May 7, 2026 08:46
nilsding
nilsding approved these changes May 7, 2026
Signed-off-by: greatjourney589 <wangkyle589@gmail.com>
@nilsding nilsding force-pushed the fix/editlocally-qassert-side-effect branch from 3db2948 to cfad288 Compare May 7, 2026 08:55
@nilsding nilsding enabled auto-merge May 7, 2026 08:55
@nilsding
Copy link
Copy Markdown
Member

nilsding commented May 7, 2026

/backport to stable-33.0

@nilsding
Copy link
Copy Markdown
Member

nilsding commented May 7, 2026

/backport to stable-4.0

@nilsding nilsding added this to the 34.0.0 milestone May 7, 2026
@github-actions
Copy link
Copy Markdown

github-actions Bot commented May 7, 2026

Artifact containing the AppImage: nextcloud-appimage-pr-9973.zip

Digest: sha256:87e5cb38cd136e8d36919e9c6a870baca154bc581901e93c5913d1d300f7c88f

To test this change/fix you can download the above artifact file, unzip it, and run it.

Please make sure to quit your existing Nextcloud app and backup your data.

@nilsding nilsding merged commit 271efdd into nextcloud:master May 7, 2026
20 of 21 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: "Edit Locally" on already-locked file shows "Lock will last for 0 minutes" in release builds

2 participants