diff --git a/backend/handlers/files.go b/backend/handlers/files.go index 276bda1..760db5b 100644 --- a/backend/handlers/files.go +++ b/backend/handlers/files.go @@ -534,11 +534,21 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error { return c.Status(fiber.StatusNotFound).JSON(fiber.Map{"error": "file not found"}) } + // Soft-delete: move to .trash directory + trashPath := filepath.Join(h.Config.TrashDir, relativePath) + // Check if permanent isPermanent := c.Query("permanent") == "true" if isPermanent { - if err := os.RemoveAll(resolvedPath); err != nil { - return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to permanently delete"}) + // Ensure we don't delete the root + if resolvedPath == c.Locals("resolvedPath").(string) && relativePath == "." { + return c.Status(fiber.StatusForbidden).JSON(fiber.Map{"error": "cannot permanently delete root"}) + } + + // Remove both potential locations to be safe + os.RemoveAll(resolvedPath) + if relativePath != "." { + os.RemoveAll(trashPath) } cleanPath := filepath.ToSlash(relativePath) @@ -547,8 +557,6 @@ func (h *FSHandler) Delete(c *fiber.Ctx) error { return c.JSON(fiber.Map{"message": "permanently deleted"}) } - // Soft-delete: move to .trash directory - trashPath := filepath.Join(h.Config.TrashDir, relativePath) if err := os.MkdirAll(filepath.Dir(trashPath), 0755); err != nil { fmt.Printf("MkdirAll error: %v\n", err) return c.Status(fiber.StatusInternalServerError).JSON(fiber.Map{"error": "failed to prepare trash"}) diff --git a/frontend/src/components/FileExplorer.tsx b/frontend/src/components/FileExplorer.tsx index 9ebd9de..a443bcc 100644 --- a/frontend/src/components/FileExplorer.tsx +++ b/frontend/src/components/FileExplorer.tsx @@ -772,7 +772,7 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) { } function handleDragOver(e: React.DragEvent) { - if (draggedFile) return; + if (draggedFile || activeSection === 'trash') return; if (!e.dataTransfer.types.includes('Files')) return; e.preventDefault(); setDragOver(true); @@ -1754,31 +1754,33 @@ export default function FileExplorer({ onLogout }: FileExplorerProps) {
- + {activeSection !== 'trash' && ( + + )} {activeSection !== 'trash' && (