Repository navigation
fix(mirror): give every page its own markdown mirror file - #13912
yuxi-liu-wired wants to merge 5 commits into
Conversation
| (if (and old-path (not= old-path new-path) (contains? new-paths old-path)) | ||
| (assoc job :old-path nil) |
There was a problem hiding this comment.
🔴 Case-only path takeover deletes another page
When Notes leaves a stem group, keep-old-paths-of-other-jobs fails to protect the surviving notes page. The old and new paths differ as strings but identify one file on macOS and Windows. Deleting the old path removes the surviving page's mirror.
Learn more
The stem index groups case variants together, so removing or renaming one page can give its old filename to another page. The protection compares paths with case-sensitive string equality, while a case-insensitive filesystem resolves both paths to the same file. <run-job! writes the surviving page and then deletes the departing page's old path. Its final file disappears regardless of which write completes first if the deletion runs last.
Example: On macOS, mirror Notes and notes; the latter uses pages/notes (2).md. Rename Notes to Other. The remaining page writes pages/notes.md, while the departing page deletes pages/Notes.md, removing that same file.
Recommended fix: Compare old and new paths using the filesystem-equivalent canonical path key, including the same page's new path. Suppress deletion whenever the old file is still an output of this batch; test case-only takeovers with a case-insensitive storage fake.
Was this helpful? React with 👍 or 👎 to provide feedback.
| 0))] | ||
| (str "pages/" (duplicate-stem (stem-index db) stem index) ".md"))))))) |
There was a problem hiding this comment.
🟡 Legacy case-variant mirror files remain stale
On Linux, page-relative-path moves an existing notes mirror to notes (2).md when Notes also exists. Neither later edits nor full regeneration removes the old notes.md. The mirror retains a stale copy of the page.
Learn more
Existing mirrors on case-sensitive filesystems can have separate files for page titles differing only by case. The new path allocation moves one of those pages to a suffixed filename. page-job derives the old path from the current naming algorithm, not the path written by the earlier version; <mirror-repo! only writes files. The old filename persists with obsolete contents even when the user regenerates the mirror.
Example: Before upgrading on Linux, Notes and notes have pages/Notes.md and pages/notes.md. After upgrading, the latter writes pages/notes (2).md, but pages/notes.md still contains the previous copy forever.
Recommended fix: Add a migration or regeneration cleanup that identifies and removes obsolete mirror files without deleting files assigned to other pages. Cover upgrading an existing case-variant mirror on a case-sensitive filesystem.
Was this helpful? React with 👍 or 👎 to provide feedback.
| (is (has-body? "bar body") "the renamed page is mirrored") | ||
| (is (has-body? "foo body") "the page whose duplicate index shifted is still mirrored") | ||
| (is (not (contains? @files (str (markdown-mirror/repo-mirror-dir test-repo) "/pages/Bar.md"))) | ||
| "the renamed page's old file is removed")) |
|
Thanks, all three were right; fixed in 39349c8, 863cbc4 and cffec58. Case-only path takeover (markdown_mirror.cljs:749). Stale legacy case-variant files (markdown_mirror.cljs:178). Regenerating the mirror now lists Rename test (markdown_mirror_collision_test.cljs:75). The test now asserts the two pages' paths ( |
83122b8 to
2b8090f
Compare
d3321a3 to
da1d1f5
Compare
da1d1f5 to
a2b9e87
Compare
…p/Down to reselect the moved rows After Alt+Shift+Down moves selected blocks out of their parent, the selection holds the rows drawn before the move until the move's delta is flushed and the new rows are reselected. A Shift+Down pressed in that gap read the old row, which is no longer in the page, found no neighbour and did nothing: the selection stayed on the moved block. Master's e2e move-across-parents-keeps-selection-test catches it (CI on logseq#13912, 2026-11-18; 20 of 36 runs on master under 6 parallel lanes). A second Alt+Shift+Up/Down already waits for the previous move through *move-up-down-tail. Shift+Up/Down (both bindings) and Up/Down on selected blocks now wait for it the same way (after-pending-move); with no move running they act at once. Test: frontend.handler.editor-move-select-test: with a move pending no selection key acts, and each acts once the move settles; without a move Shift+Down acts at once. Fails without the change, passes with it. move-across-parents-keeps-selection-test under 6 lanes: 0 of 36 failed with the change.
a2b9e87 to
d653fc5
Compare
…p/Down to reselect the moved rows After Alt+Shift+Down moves selected blocks out of their parent, the selection holds the rows drawn before the move until the move's delta is flushed and the new rows are reselected. A Shift+Down pressed in that gap read the old row, which is no longer in the page, found no neighbour and did nothing: the selection stayed on the moved block. Master's e2e move-across-parents-keeps-selection-test catches it (CI on logseq#13912, 2026-11-18; 20 of 36 runs on master under 6 parallel lanes). A second Alt+Shift+Up/Down already waits for the previous move through *move-up-down-tail. Shift+Up/Down (both bindings) and Up/Down on selected blocks now wait for it the same way (after-pending-move); with no move running they act at once. Test: frontend.handler.editor-move-select-test: with a move pending no selection key acts, and each acts once the move settles; without a move Shift+Down acts at once. Fails without the change, passes with it. move-across-parents-keeps-selection-test under 6 lanes: 0 of 36 failed with the change.
…p/Down to reselect the moved rows After Alt+Shift+Down moves selected blocks out of their parent, the selection holds the rows drawn before the move until the move's delta is flushed and the new rows are reselected. A Shift+Down pressed in that gap read the old row, which is no longer in the page, found no neighbour and did nothing: the selection stayed on the moved block. Master's e2e move-across-parents-keeps-selection-test catches it (CI on logseq#13912, 2026-11-18; 20 of 36 runs on master under 6 parallel lanes). A second Alt+Shift+Up/Down already waits for the previous move through *move-up-down-tail. Shift+Up/Down (both bindings) and Up/Down on selected blocks now wait for it the same way (after-pending-move); with no move running they act at once. Test: frontend.handler.editor-move-select-test: with a move pending no selection key acts, and each acts once the move settles; without a move Shift+Down acts at once. Fails without the change, passes with it. move-across-parents-keeps-selection-test under 6 lanes: 0 of 36 failed with the change.
What happened: in the markdown mirror, two pages could map to one file, so one page's content replaced the other's or was missing: titles differing only in case (`Notes`, `notes`) are one file on macOS and Windows; a page titled `Foo (2)` and the second page titled `Foo` both used `pages/Foo (2).md`; and renaming a page into an existing title, or deleting one, shifted the other pages' ` (n)` numbers without rewriting them, so the renamed page overwrote the other page's file. Cause: `page-relative-path` grouped pages by their exact stem, appended ` (n)` without checking whether another page owns that name, and `<handle-tx-report!` only rewrote the pages the tx touched. Change: pages are grouped by the lower-cased stem; a ` (n)` suffix that another page has as its own title is skipped; a tx also rewrites every page in the stem groups it changed (and the groups whose suffix skips them), and a page does not delete its old file when that path is now another page's file. Test: `frontend.worker.markdown-mirror-collision-test` covers the case, literal-suffix and rename cases.
What happened: on macOS and Windows, mirroring `Notes` and `notes` puts `notes` at `pages/notes (2).md`; renaming `Notes` to `Other` moves `notes` to `pages/notes.md`, and the renamed page then deleted its old file `pages/Notes.md`, which is the same file, so `notes` had no mirror file. Renaming `notes` to `Notes` likewise wrote `pages/Notes.md` and then deleted `pages/notes.md`, the page's own new file. Cause: `keep-old-paths-of-other-jobs` kept an old path only when it was equal, as a string, to another job's new path, while stem groups (and case-insensitive file systems) treat case variants as one name. Change: old paths are compared with the batch's new paths by the lower-cased path, including the page's own new path; an old path that is still an output of the batch is not deleted. Test: `a-departing-page-keeps-the-file-a-case-variant-takes-over-test` and `a-case-only-rename-keeps-the-page-file-test` in `frontend.worker.markdown-mirror-collision-test` run against a case-insensitive storage fake whose deletes land after the batch's writes.
What happened: a mirror written on Linux before this branch can hold both `pages/Notes.md` and `pages/notes.md`. With case variants grouped, `notes` moves to `pages/notes (2).md`, and the old `pages/notes.md` kept a stale copy of the page forever: page jobs derive the old path from the current naming, and regenerating the mirror only wrote files. Change: regenerating the mirror lists `pages/` and `journals/` and deletes the `.md` files no mirrored page owns. After each write batch, the path a written page had under the previous naming (exact-stem groups), and an old path kept because it differs only in case from a path the batch wrote, are deleted when they exist and no page owns them. A file that differs only in case from a page's path that is not listed itself is that page's file on a case-insensitive file system and is kept. The node platform gets `:read-dir!` (file names in a mirror directory); a platform without it skips the cleanup. Test: `regenerating-removes-a-legacy-case-variant-file-test` and `writing-a-moved-page-removes-its-legacy-file-test` (case-sensitive fake holding both legacy files), `regenerating-keeps-a-page-file-listed-under-another-case-test` (case-insensitive fake), and `node-platform-reads-mirror-dir-file-names-test`.
The rename test only checked that both page bodies exist somewhere in the mirror, so it passed if the two pages' contents were swapped. It now asserts the pages' paths (`pages/Foo.md`, `pages/Foo (2).md`) and that each path holds its own page's body.
A page whose title matches a property's name up to case (the page Source and the property source) was mirrored to pages/Source (2).md instead of pages/Source.md. The properties have no mirror file, so the suffix guarded against nothing, and a reader of the files saw the page under another name: re-importing the mirror gave a page titled "Source (2)", so its block refs and embeds were no longer found on the page named Source. Cause: the stem index that assigns the ` (n)` suffixes held every non-journal page, including properties, built-in and hidden pages that are never written. Once pages are grouped by the lower-cased stem, any page named like a property shares a group with it. Change: only pages that are mirrored (mirrorable-page?) enter the stem index and the legacy-path grouping; mirrorable-page? and contents-page? move up next to the stem code that now uses them. Test: a-property-without-a-file-does-not-take-a-page-file-name-test in markdown_mirror_collision_test.cljs checks that the page Source keeps pages/Source.md next to the property source.
d653fc5 to
c236e2e
Compare
…p/Down to reselect the moved rows After Alt+Shift+Down moves selected blocks out of their parent, the selection holds the rows drawn before the move until the move's delta is flushed and the new rows are reselected. A Shift+Down pressed in that gap read the old row, which is no longer in the page, found no neighbour and did nothing: the selection stayed on the moved block. Master's e2e move-across-parents-keeps-selection-test catches it (CI on logseq#13912, 2026-11-18; 20 of 36 runs on master under 6 parallel lanes). A second Alt+Shift+Up/Down already waits for the previous move through *move-up-down-tail. Shift+Up/Down (both bindings) and Up/Down on selected blocks now wait for it the same way (after-pending-move); with no move running they act at once. Test: frontend.handler.editor-move-select-test: with a move pending no selection key acts, and each acts once the move settles; without a move Shift+Down acts at once. Fails without the change, passes with it. move-across-parents-keeps-selection-test under 6 lanes: 0 of 36 failed with the change.
The markdown mirror (
<graph>/mirror/markdown/pages/) can map two pages to one file, so a page silently goes missing from the mirror (one page's file holds another page's content, or a page has no file until it is edited again), and deleting one page can delete the file both share. Users who keep the mirror as a backup or in git lose a page from it. The DB is not affected.How it happens
Notesandnotes(e.g.Work/NotesandHome/notes) are written topages/Notes.mdandpages/notes.md, one file on macOS (APFS default) and Windows.Foo (2)and the second page titledFooboth map topages/Foo (2).md.FooandBarare mirrored; renamingBar(uuid sorting first) toFoogives it index 1 and it writes over the otherFoo's file, which is not among the affected pages and is never rewritten.Change
src/main/frontend/worker/markdown_mirror.cljs:(n), a suffixed stem that another page has as its own title is skipped;Test
frontend.worker.markdown-mirror-collision-testcovers the three cases. On master it fails in all three (pages/notes.mdtwice by case, 2 distinct paths for 3 pages,foo bodymissing after the rename); with the change it passes. CI's unit suite passes.Added: review follow-ups
NotestoOthermovednotesfrompages/notes (2).mdtopages/notes.md, and the renamed page then deleted its oldpages/Notes.md, which is the same file. A case-only rename (notestoNotes) deleted the page's own new file the same way. Old paths are now compared with every new path of the batch, the page's own included, by the lower-cased path, and an old path that is still an output of the batch is kept.pages/Notes.mdandpages/notes.md;notesnow writespages/notes (2).md, andpages/notes.mdstayed as a stale copy. Regenerating the mirror now deletes the.mdfiles inpages/andjournals/that no page owns, and after each write batch the path a written page had under the previous naming is deleted when it exists and no page owns it. A file that differs only in case from a page's path that is not listed itself is that page's file on a case-insensitive file system and is kept. The node platform gets:read-dir!to list a mirror directory; a platform without it skips the cleanup.frontend.worker.markdown-mirror-collision-testadds the case-insensitive takeover and case-only rename cases, the upgrade case on a case-sensitive fake (regeneration and the first write), the regeneration case on a case-insensitive fake, and:read-dir!on the node platform; the rename test now asserts each page's content at its assigned path.Added: pages that are not mirrored do not take a file name
Sourcenext to the propertysource) was mirrored topages/Source (2).mdinstead ofpages/Source.md. Re-importing the mirror then gave a page titledSource (2), so the block refs and embeds onSourcewere no longer found under that page. This showed up when this PR is combined with fix(export): text, markdown, mirror and embeds #13869, whosepage-mirror-writes-block-refs-embeds-and-node-values-by-block-id-testhas exactly that page and property.(n)suffixes held every non-journal page, including properties and built-in or hidden pages, which are never written. With pages now grouped by the lower-cased stem, a page sharing a property's name up to case got pushed to a suffixed file to avoid a file that does not exist.mirrorable-page?) enter the stem index and the legacy-path grouping.a-property-without-a-file-does-not-take-a-page-file-name-testinfrontend.worker.markdown-mirror-collision-test(fails before the change withpages/Source (2).md).frontend.worker.markdown-mirror-testpasses on this branch alone and on this branch merged with fix(export): text, markdown, mirror and embeds #13869.