fix(folders): keep folder share, rename and delete to that folder

CO
18h ago
+325-41

Summary

Context: Folder operations matched a folder's descendants with SQL LIKE '<path>/%'. In LIKE, _ and % are wildcards and ASCII case is ignored. Sharing Q1_2026 therefore also uploaded the notes in Q1-2026/… and q1_2026/… to the folder's recipients. Renaming or deleting Q1_2026 moved, unfiled or tombstoned those look-alike folders' notes, subfolders and attachments.

Intention: A folder operation must affect only that folder and what is literally inside it, so nothing leaks into a share and other folders don't change.

Direction:

  • The db-app folder catalog operations used by tauri-plugin-session (rename, delete, attachment and workspace lookups) now match the folder itself or a literal path prefix followed by / or \.
  • In the desktop app, the shared-folder payload and folder deletion keep only notes literally inside the folder, using a literal isInFolder check. It doesn't normalize or validate paths, so descendants that a parent rename made longer than 200 characters still count. The folder-name check matches literally too.
  • Sidebar folder listings already filtered literally, so they're unchanged.

This was found in a code review of the native GPUI app, whose copy of the query is being fixed separately.

Demo

N/A — data-scoping fix covered by regression tests; no UI change.

Verification

Local, macOS:

  • Rust, from a git archive export of main plus this change:
    • cargo test --locked -p db-app --lib: 286 passed. The new folder_operations_match_paths_literally test covers sessions, folders and attachments under rename and delete. It fails on the old queries, where renaming Q1_2026 moved the Q1-2026, Q1%2026 and q1_2026 notes.
    • cargo test --locked -p tauri-plugin-session: 38 passed.
    • cargo clippy --locked -p db-app -p tauri-plugin-session --all-targets --no-deps -- -D warnings: clean.
  • Desktop:
    • pnpm -F @anlg/desktop typecheck passes.
    • pnpm -F @anlg/desktop test: 4,280 of 4,282 pass. The two failures are in src/stt/primary-device.test.tsx; that file passes alone (15/15) and touches nothing here. It failed under full-suite load in a working tree that holds other in-progress changes.
    • New tests: the folder payload shares only the folder's own notes; deleting a folder moves only its own notes, including a descendant whose path is over 200 characters (19 tests across the payload and folder suites).
  • dprint check passes on the changed files.

Summary by cubic

Fixes folder share, rename, and delete so they affect only the named folder and its literal descendants. Previously these operations used SQL LIKE matching, where _ and % are wildcards and ASCII case is ignored, so acting on Q1_2026 also included notes from Q1-2026, q1_2026, and Q1%2026 in shares, renames, and deletions.

  • db-app folder catalog operations now match the folder itself or a literal path prefix followed by / or \.
  • Desktop folder deletion and shared payloads keep only notes literally inside the folder with a new isInFolder check that accepts descendant paths longer than 200 characters a parent rename can produce.
  • Shared copies keep a renamed note's subfolder: the relative path comes from only the part below the folder, and the share is refused when that part can't be represented.
  • Importing a shared copy now validates every destination path first and refuses it before creating anything, so a too-long nested folder isn't filed unfiled.
  • The folder-name check now matches literally instead of with LIKE.
  • Added regression tests covering rename, delete, share, and attachment rename/delete next to look-alike folders.