recycle_bin.move_to_trash is now the only way the plugin deletes the user's files: SHFileOperationW with FOF_ALLOWUNDO on fixed Windows drives (send2trash or gio elsewhere). Where there is no Recycle Bin (USB stick, network share) it raises TrashUnavailable and nothing is deleted; the API says so (api/trash.trash_failure), including "file in use". Routed through it: model delete (model + sidecars in one operation, or nothing), cover replacement and cover reset, output images, generated audio, recipes with history and images, materials with images, prompt notes, parameter notes, the duplicate copy a physical rename finds and the covers a forced rescan replaces. Temp files, caches and the bounded recipe history are still removed directly. The unused POST /anomalous/clean_civitai_info, which erased every .civitai.info in the library (with the names users set), is removed with its activity-log label. Delete confirmations say where things go. Tests use a fake Recycle Bin (none of their files reach the real one). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
20 lines
1.1 KiB
Python
20 lines
1.1 KiB
Python
"""The API's way to delete the user's files: recycle_bin.py (shared with the scanner)."""
|
|
|
|
try:
|
|
from ..recycle_bin import TrashUnavailable, move_to_trash
|
|
except ImportError: # loaded outside the package (tests)
|
|
from recycle_bin import TrashUnavailable, move_to_trash
|
|
|
|
__all__ = ["TrashUnavailable", "move_to_trash", "trash_failure"]
|
|
|
|
|
|
def trash_failure(exc):
|
|
"""What to tell the user when moving to the Recycle Bin did not happen."""
|
|
if isinstance(exc, TrashUnavailable):
|
|
return ("这个位置没有回收站(U 盘或网络盘),为了安全没有删除,请在文件管理器里手动删除。"
|
|
" / No Recycle Bin here (USB or network drive); nothing was deleted, please delete it in your file manager.")
|
|
if getattr(exc, "errno", None) == 32 or getattr(exc, "winerror", None) == 32 or "being used" in str(exc):
|
|
return ("文件正在被使用(可能 ComfyUI 已经加载了它),没有删除。请先卸载模型或重启 ComfyUI。"
|
|
" / The file is in use (ComfyUI may have it loaded); nothing was deleted.")
|
|
return f"没有删除 / Not deleted: {exc}"
|