Skip to content

[BUG] External file changes are not detected if file is overwritten by move #3468

Done

Description

@jkhsjdhjs

Issue Description

QOwnNotes doesn't detect modifications of notes if they're synced by the Nextcloud desktop client or more generally, if they're performed by a move operation. This was already discussed in #3366, but now I finally had some time to investigate this issue further.

Nextcloud Desktop File Synchronization

When the Nextcloud desktop client syncs changes to an already-existing file, it doesn't overwrite it directly.
Instead, it first creates a temporary file .<name-of-note>.~<unique-id>, e.g. .Welcome to QOwnNotes.md.~dce5e2c.
All remote changes are written to this file first. Only afterwards, the original note file is overwritten by a move to finalize the synchronization.

So why are these changes not detected by QOwnNotes?

QOwnNotes File Change Detection

QOwnNotes uses two kinds of filesystem watchers: a directory watcher and a file watcher:

void MainWindow::connectFileWatcher(bool delayed) {
if (!delayed) {
connect(&noteDirectoryWatcher, &QFileSystemWatcher::directoryChanged, this,
&MainWindow::notesDirectoryWasModified, Qt::UniqueConnection);
connect(&noteDirectoryWatcher, &QFileSystemWatcher::fileChanged, this,
&MainWindow::notesWereModified, Qt::UniqueConnection);
} else {
// In some cases, there are delayed signals coming in which we don't want to handle
// so reconnect with delay
QTimer::singleShot(300, this, [this] {
connect(&noteDirectoryWatcher, &QFileSystemWatcher::directoryChanged, this,
&MainWindow::notesDirectoryWasModified, Qt::UniqueConnection);
connect(&noteDirectoryWatcher, &QFileSystemWatcher::fileChanged, this,
&MainWindow::notesWereModified, Qt::UniqueConnection);
});
}
}

The directory watcher is attached to the note directory and the file watcher to every note.
On a directory event (i.e. the creation of a new file), the notesDirectoryWasModified callback is called.
If a file is changed, notesWereModified is called instead.

Control Flow during Synchronization

If the Nextcloud client syncs a file, QOwnNotes' notesDirectoryWasModified callback is run first, since the Nextcloud desktop client first creates the temporary file. This callback also contains a workaround to call notesWereModified for the currently active note. However, since the Nextcloud client at this point only created the temporary file, the currently active note hasn't been modified yet. Thus, notesWereModified returns early. Afterwards, the temporary note file is modified by the Nextcloud sync client, which triggers notesDirectoryWasModified again for some reason, with the same result: no changes were detected because no changes to the actual note were performed yet.

Finally, the Nextcloud sync client moves the temporary note to the location of the actual note, thereby overwriting it. This triggers notesDirectoryWasModified again, but it still doesn't detect any changes, although they would be detectable by now. This is because before calling notesWereModified, notesDirectoryWasModified first rebuilds and reloads the note directory list, which results in the changes not being detected for some reason.

QOwnNotes/src/mainwindow.cpp

Lines 3112 to 3123 in 025e685

// rebuild and reload the notes directory list
buildNotesIndexAndLoadNoteDirectoryList();
// check if the current note was modified
// this fixes not detected external note changes of the current note if the
// event for the change in the current note comes after the event that the
// note folder was modified
QString noteFileName = currentNote.getFileName();
if (!noteFileName.isEmpty()) {
// Use the full path, like a filesystem watcher would, instead of just the file-name
notesWereModified(currentNote.fullNoteFilePath());
}

Moving the call to buildNotesIndexAndLoadNoteDirectoryList() after notesWereModified() makes the detection functional. However, I'm not sure if this has additional unwanted side-effects.

This final move operation also triggers notesWereModified directly, because in addition to the notes directory, files are also watched. However, since the note index has been reloaded and rebuilt, no changes are detected here as well.

Another issue results from how Qt handles file replacements. Nextcloud overwriting the note file via a move operation destroys the original file's inode. This causes QFileSystemWatcher to silently detach from the note. The watcher is never reattached to the new inode, meaning subsequent modifications to that note are completely ignored.

Summary

In summary, there are two important issues with the change detection the way it's currently implemented:

  1. Rebuilding the notes index breaks the change detection
  2. File watchers aren't reattached if files are overwritten

As I don't know much about the inner workings of the note index, I don't have a suggestion for a fix there.
However, the second issue could be fixed by re-adding files to the noteDirectoryWatcher after they have been overwritten.

Related Issues

#3366
#3428 @ohnemich

Activity

  1. pbek commented on Feb 23, 2026

    @pbek
    Owner

    Well researched issue. 😉

    However, the second issue could be fixed by re-adding files to the noteDirectoryWatcher after they have been overwritten.

    The main issue here is that for the QFileSystemWatcher to notify you about changes of a file, you actively need to subscribe to it for that file. And if that file goes away, the watcher goes away too.

    And a secondary issue is that you may not always get notifications anyway, because of OS limitations.

    Moving the call to buildNotesIndexAndLoadNoteDirectoryList() after notesWereModified() makes the detection functional.

    Did you test that? I'm not sure why it should... And of course this will have side effects. 🤔

  2. added
    Severity: Low
    and removed on Feb 23, 2026
  3. jkhsjdhjs commented on Feb 23, 2026

    @jkhsjdhjs
    Author

    The main issue here is that for the QFileSystemWatcher to notify you about changes of a file, you actively need to subscribe to it for that file. And if that file goes away, the watcher goes away too.

    Yep, but the watcher can easily be reattached, since the directory is monitored anyway. The problem is, that this is currently not implemented.

    And a secondary issue is that you may not always get notifications anyway, because of OS limitations.

    I'm not aware of that (on Linux at least). In my testing I always got inotify events, they just weren't handled by QOwnNotes since buildNotesIndexAndLoadNoteDirectoryList() is called before notesWereModified(), blocking the detection for some reason. Furthermore, subsequent events are not received by QOwnNotes at all since the watcher is not reattached to new files.

    Did you test that? I'm not sure why it should... And of course this will have side effects. 🤔

    Yep! I tested all of the statements in my bug report. I'm also not sure why running buildNotesIndexAndLoadNoteDirectoryList() first would mess with the detection, but yes, that's the case.

  4. pbek commented on Feb 23, 2026

    @pbek
    Owner

    I can reproduce your issue only if the note you change via sync is not the current note. If it is the current note, then I get an instant update.
    But moving the statement as you suggested didn't fix that for me.

  5. jkhsjdhjs commented on Feb 23, 2026

    @jkhsjdhjs
    Author

    Hmm, that's odd. I only tested with the currently active note for this bug report.

    So what's the difference between our setups?
    I'm on Arch Linux (Linux 6.18.9-arch1-2) with Nextcloud desktop 4.0.6 on an ext4 filesystem. As for QOwnNotes, I used the latest git master in debug mode during testing.

  6. pbek commented on Feb 23, 2026

    @pbek
    Owner

    And I guess the note will not be updated, because the sync client starts to write the temporary file, triggers MainWindow::notesDirectoryWasModified and then when buildNotesIndexAndLoadNoteDirectoryList is done the changed note gets moved and doesn't trigger anything else. 🤔

  7. jkhsjdhjs commented on Feb 23, 2026

    @jkhsjdhjs
    Author

    when buildNotesIndexAndLoadNoteDirectoryList is done the changed note gets moved and doesn't trigger anything else. 🤔

    The moved note still triggers the filesystem watcher, but I could see that notesWereModified does not detect any changes in the file, even though the file did in fact change.

  8. pbek commented on Feb 23, 2026

    @pbek
    Owner

    So what's the difference between our setups?

    NixOS Unstable on ZFS. Kernel 6.18.12. Nextcloud desktop 4.0.6. QOwnNotes from main branch with debug.

  9. jkhsjdhjs commented on Feb 23, 2026

    @jkhsjdhjs
    Author

    @ohnemich Maybe you could also post your setup here? My current guess is that there's a difference on how the events are emitted on different filesystems. Maybe I'll have time to test on ZFS in the next days.

  10. pbek commented on Feb 23, 2026

    @pbek
    Owner

    Maybe you could also post your setup here?

    On what part of my setup are you interested in?

  11. added a commit that references this issue on Feb 23, 2026
  12. pbek commented on Feb 23, 2026

    @pbek
    Owner

    26.2.10

    • Fixed Nextcloud desktop client sync changes to non-current note files not being picked up by QOwnNotes
      (for #3468)
      • The Nextcloud client uses a temp-file + atomic rename strategy to update note files; the rename
        typically completes before the directoryChanged signal handler runs, so the temp file is already
        gone when QOwnNotes looks for it — the deferred re-index was therefore never triggered
      • The notes directory watcher now always schedules a deferred re-index (1 second after the directory
        change event) so the final on-disk state of all note files is captured regardless of whether a
        temp file is visible at the time the event fires
      • The note index rebuild also refreshes the note list when an existing note's content was updated
        on disk, not only when notes were added or removed

    Sets see how many side effects that change has... 😊

  13. 11 remaining items

  14. added a commit that references this issue on Feb 25, 2026
  15. pbek commented on Feb 25, 2026

    @pbek
    Owner

    I tried to do some more stuff...

    26.2.12

    • Improved detection of current note updates when the Nextcloud desktop client replaces files via
      temp file moves (for #3468)
  16. pbek commented on Feb 25, 2026

    @pbek
    Owner

    There now is a new release, could you please test it and report if it works for you?

  17. ohnemich commented on Feb 26, 2026

    @ohnemich

    Sorry, I do not receive the notification modification dialog reliable and I can't make out, why it is, I don't have a clue.
    Appreciating your immediate reaction to the issue - thank you very much-, I have to admit, that I do not have the time to test in depth. Maybe @jkhsjdhjs or @wolframroesler (submitted issue in #3366 ) can test further, I'll give an update of my latest tests below.

    Today I made round about 30 tests.
    Started with update QOwnnote update. After update, modification notifications were shown. Notes were in my unsynced users documents folders notes, made about 10 tests changing notes with notepad++ and Qownnotes.
    Restarted QOWnnote, chose nextcloud notes folder in Qownnotes. Modification notifications were shown only a few times with about 20 tests at the beginning, at the end of the test, they were not shown anymore at all.

  18. pbek commented on Feb 26, 2026

    @pbek
    Owner

    Thank you for the update. I myself can't reproduce the issue anymore.

  19. jkhsjdhjs commented on Feb 27, 2026

    @jkhsjdhjs
    Author

    I just tested it again with QOwnNotes - version 26.2.13 - AUR - build 1270, but I still experience the same behavior as before, i.e. changes are applied by the nextcloud desktop client, but QOwnNotes only shows Notes directory was modified.

  20. pbek commented on Jun 24, 2026

    @pbek
    Owner

    but QOwnNotes only shows Notes directory was modified

    That can also mean there are not enough filesystem watchers available on the syst️em. 🤷🏻

  21. pbek commented on Nov 24, 2026

    @pbek
    Owner

    Is this still an issue?

  22. jkhsjdhjs commented on Nov 25, 2026

    @jkhsjdhjs
    Author

    Yep, I can still reproduce it with QOwnNotes - version 26.11.15 - AUR - build 1424

  23. pbek commented on Nov 26, 2026

    @pbek
    Owner

    Thanks for retesting. The next release (26.11.16) will include the fix from #3862 for external updates that replace an open note by renaming a temporary file over it. QOwnNotes will check the replacement against the version last loaded or saved by the editor, and autosave will no longer write stale editor text back merely because the file changed on disk.

    We verified two consecutive replacements on Linux without Nextcloud. Once 26.11.16 is available, could you try two successive Nextcloud updates to the same open, unedited note, without switching notes? Please let us know whether both changes show up and stay on disk after autosave. If either change does not appear, does switching away and back show the new text? We’ll keep this issue open until we confirm the Nextcloud case.

  24. pbek commented on Nov 26, 2026

    @pbek
    Owner

    There now is a new release, could you please test it and report if it works for you?

  25. jkhsjdhjs commented on Nov 27, 2026

    @jkhsjdhjs
    Author

    @pbek Crazy, yes, I just tested it again, it detects all modifications of the current note just fine now! I tested multiple consecutive external edits via Nextcloud of the same, unedited note, works fine! Furthermore, edits of an already-edited note file also work fine now! Thanks a lot, I guess this issue can be closed then! :D

  26. pbek commented on Nov 28, 2026

    @pbek
    Owner

    Thank you very much for testing!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Can't reproduceSeverity: LowType: Upstream-problem

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions