review 06/07/08: loeschen in papierkorb, backup-erfolg ehrlich, verschieben sicher

08 Loeschen: statt fs.rmSync (endgueltig) jetzt in den Windows-Papierkorb
   (wiederherstellbar, Pfad per env an PowerShell -> keine Shell-Injektion);
   schlaegt es fehl, bleibt das Projekt. _Tools-Schutz case-insensitiv.
   Dialog nennt Papierkorb + letzten Backup-Stand.
06 Backup: Kopier-Entscheidung + Erfolg am Robocopy-Exitcode statt nur an
   geparsten Konsolenzeilen; bei unklarem Ergebnis kein gruener Stand, sondern
   'Ergebnis unklar' + sicherheitshalber kopieren. README: Wiederherstellung,
   Ueberschreiben desselben Ziels, Papierkorb.
07 Verschieben: Original erst nach verifizierter, nicht-leerer Uebernahme
   entfernen; Entfernen-Fehler laesst beide Staende nutzbar. Case-only-Umbenennen
   rollt bei Fehler im zweiten Schritt zurueck bzw. meldet den Zwischenpfad.

Getestet: Papierkorb-Loeschung eines Wegwerf-Ordners -> landet wiederherstellbar
im Papierkorb. node --check alle Dateien, i18n-Paritaet 801/801.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-11-30 00:24:08 +01:00
parent c7e8ad6634
commit 916d6b8685
10 changed files with 78 additions and 25 deletions

View File

@@ -980,7 +980,18 @@ app.post('/api/projects/:name/clean', handle(async (req, res) => {
res.json(result)
}))
// Permanently deletes the whole project folder from disk (not from any backup).
// Moves the whole project folder to the Windows Recycle Bin (recoverable, not a permanent wipe).
// Path is passed via an env var, so it never goes through a shell. On any failure the folder stays.
function recycleToBin(target) {
const script =
'Add-Type -AssemblyName Microsoft.VisualBasic;' +
"try { [Microsoft.VisualBasic.FileIO.FileSystem]::DeleteDirectory($env:PD_RECYCLE_TARGET,'OnlyErrorDialogs','SendToRecycleBin'); exit 0 }" +
'catch { [Console]::Error.WriteLine($_.Exception.Message); exit 1 }'
return run('powershell', ['-NoProfile', '-NonInteractive', '-ExecutionPolicy', 'Bypass', '-Command', script],
{ env: { ...process.env, PD_RECYCLE_TARGET: target }, timeout: 120000 })
}
// Deletes the whole project folder into the Recycle Bin (not from any backup).
// Guarded: only a real subfolder of a shown projects folder, never a root or _Tools.
app.post('/api/projects/:name/delete', handle(async (req, res) => {
if (storage.busy() || backup.busy() || create.busy() || archive.busy()) return res.status(409).json({ error: 'Erst warten, bis Scan/Backup fertig ist.' })
@@ -988,17 +999,18 @@ app.post('/api/projects/:name/delete', handle(async (req, res) => {
const dir = resolveProject(key)
const ref = dir && projectRef(key)
if (!ref || !dir) return res.status(404).json({ error: 'unknown project' })
if (ref.folder === '_Tools') return res.status(400).json({ error: '_Tools wird nie gelöscht' })
// protect _Tools regardless of upper/lowercase spelling (Windows path semantics)
if (ref.folder.toLowerCase() === '_tools') return res.status(400).json({ error: '_Tools wird nie gelöscht' })
const root = path.resolve(ref.root.path)
const target = path.resolve(dir)
// never the projects folder itself, never a drive root – only a subfolder of a registered root
if (target.toLowerCase() === root.toLowerCase() || !target.toLowerCase().startsWith(root.toLowerCase() + path.sep) || path.dirname(target) === target) {
return res.status(400).json({ error: 'Ordner nicht löschbar.' })
}
try {
fs.rmSync(target, { recursive: true, force: true, maxRetries: 5, retryDelay: 200 })
} catch (e) {
return res.status(400).json({ error: `Löschen fehlgeschlagen (Datei gesperrt? Programm offen?): ${String(e.message ?? e)}` })
const r = await recycleToBin(target)
if (!r.ok || fs.existsSync(target)) {
const why = (r.stderr || '').trim() || (fs.existsSync(target) ? 'Ordner noch vorhanden (Datei gesperrt? Programm offen?)' : 'unbekannt')
return res.status(400).json({ error: `Verschieben in den Papierkorb fehlgeschlagen – das Projekt bleibt erhalten: ${why}` })
}
// drop it from the subfolder-scanner lists if it was listed there
const rSet = settings.get().roots.find((x) => x.id === ref.root.id)