Move workspace file work off the main thread and delete to the trash

Run the blocking workspace commands on the blocking thread pool.
Tauri runs a synchronous command on the main thread, so a long search
or copy froze every window. Command names, arguments, and results do
not change.

Send each workspace-event only to the windows that have its root open.
The frontend listens with its window label as the target. Do not send
access events, because the frontend ignores them. Drop watchers after
the state lock is released, because a macOS watcher waits for its
thread when it stops.

Fix these defects. Each fix has a Rust test:
- A rename that changes only the letter case works on case-insensitive
  volumes.
- New files publish with a move that never replaces a file: MoveFileExW
  on Windows, renameat2 or renamex_np on Linux and macOS, then a hard
  link, then create_new. exFAT, FAT32, and many network mounts now work.
  The Windows save recovery uses the same move.
- On macOS and Linux, existing names with a colon stay usable. New names
  reject the characters that Windows does not allow, on every platform.
- workspace_read_data_url checks the size before it reads the file.
- workspace_write_bytes uses the atomic writer. Its only caller writes
  new names, so it gets no conflict check.
- Delete and rename act on a link itself, not on its target.

Delete now moves items to the system trash. One file moves without a
confirmation. A folder or several items need one. Shift+Delete and
"Delete permanently" keep the permanent delete with its confirmation.
Windows drives without a Recycle Bin give an error instead of a silent
permanent delete. The smoke test for tree actions now checks this
behavior. The user guide describes it and the new-name rule.
This commit is contained in:
Knotty Wyvern
2026-10-27 23:15:14 -07:00
parent 2448c68abf
commit a0eef01ed0
9 changed files with 978 additions and 127 deletions
+45 -8
View File
@@ -449,6 +449,18 @@
return;
}
}
// Delete moves the selection to the trash. Shift+Delete deletes it permanently.
// macOS keyboards: Cmd+Backspace and Cmd+Option+Backspace, as in Finder.
const deleteKey = event.key === "Delete" && !event.ctrlKey && !event.metaKey && !event.altKey;
const macDeleteKey = event.key === "Backspace" && event.metaKey && !event.ctrlKey && !event.shiftKey;
if ((deleteKey || macDeleteKey) && event.target instanceof Element && treeElement?.contains(event.target)
&& !event.target.closest('input, textarea, [contenteditable="true"]')) {
const entries = [...selection.paths].map(findEntry).filter((entry): entry is TreeEntry => !!entry);
if (!entries.length) return;
event.preventDefault(); event.stopPropagation();
void deleteEntries(entries, deleteKey ? event.shiftKey : event.altKey);
return;
}
if (event.key !== "F2" || event.ctrlKey || event.metaKey || event.altKey) {
return;
}
@@ -682,21 +694,40 @@
onStatus?.(`Copied ${result.completed.length} of ${roots.length} items`);
}
async function deleteEntries(entries: TreeEntry[]) {
// Delete moves items to the system trash. One file needs no confirmation, because the
// trash can restore it. A folder or several items need one. A permanent delete
// (Shift+Delete, or "Delete permanently" in the menu) always asks first.
function deleteQuestion(entries: TreeEntry[], roots: TreeEntry[], permanent: boolean): string | null {
if (entries.length === 1) {
const name = entries[0].name;
if (entries[0].kind === "folder") return $t(permanent ? "Permanently delete {name} and everything inside it?" : "Move {name} and everything inside it to the trash?", { name });
return permanent ? $t("Permanently delete {name}?", { name }) : null;
}
const folders = entries.some(entry => entry.kind === "folder");
const question = permanent
? $t(folders ? "Permanently delete {count} selected items and all contents of selected folders?" : "Permanently delete {count} selected items?", { count: entries.length })
: $t(folders ? "Move {count} selected items and all contents of selected folders to the trash?" : "Move {count} selected items to the trash?", { count: entries.length });
return question + "\n\n" + roots.map(entry => entry.rel_path).join("\n");
}
async function deleteEntries(entries: TreeEntry[], permanent = false) {
if (!entries.length) return;
const roots = selectionRoots(entries);
const message = entries.length === 1
? $t(entries[0].kind === "folder" ? "Permanently delete {name} and everything inside it?" : "Permanently delete {name}?", { name: entries[0].name })
: $t(entries.some(entry => entry.kind === "folder") ? "Permanently delete {count} selected items and all contents of selected folders?" : "Permanently delete {count} selected items?", { count: entries.length }) + "\n\n" + roots.map(entry => entry.rel_path).join("\n");
const question = deleteQuestion(entries, roots, permanent);
try {
if (!await confirm(message, { title: $t("Delete from disk"), kind: "warning" })) return;
if (question && !await confirm(question, { title: $t(permanent ? "Delete from disk" : "Move to trash"), kind: "warning" })) return;
const result = await runTreeActions(roots, async entry => {
await workspaceDelete(entry.rel_path);
await workspaceDelete(entry.rel_path, permanent);
forgetFolder(entry.rel_path);
onEntryGone?.(entry.rel_path);
});
for (const parent of new Set(roots.map(entry => parentRel(entry.rel_path)))) await load(parent);
error = result.failures.length ? result.failures.join("\n") : null;
onStatus?.($t("Deleted {count} of {total} items", { count: result.completed.length, total: roots.length }));
// The trash can be unavailable, for example on a network drive. A permanent delete stays an explicit choice.
const hint = !permanent && result.failures.length ? [$t("To delete permanently instead, select the items and press Shift+Delete.")] : [];
error = result.failures.length ? [...result.failures, ...hint].join("\n") : null;
onStatus?.(permanent
? $t("Deleted {count} of {total} items", { count: result.completed.length, total: roots.length })
: $t("Moved {count} of {total} items to the trash. Restore them from the system trash.", { count: result.completed.length, total: roots.length }));
} catch (err) {
error = err instanceof Error ? err.message : String(err);
}
@@ -875,6 +906,12 @@
icon: "trash",
run: () => { void deleteEntries(entries); },
},
{
kind: "action",
label: multiple ? $t("Delete permanently ({count})", { count: entries.length }) : $t("Delete permanently"),
icon: "trash",
run: () => { void deleteEntries(entries, true); },
},
];
}
</script>