Skip to content

obsidian/vault-delete

This module provides deletion utilities that require metadata cache access.

InterfaceDescription
RescueStillUsedFileParamsParameters passed to DeleteIfNotUsedParams.rescueStillUsedFile.
FunctionDescription
deleteIfNotUsedDeletes an abstract file safely from the vault, but only if it is not referenced by other notes. Backlinks originating from DeleteIfNotUsedParams.deletedNotePath and DeleteIfNotUsedParams.deletedNotePaths are discounted before deciding whether a file is still used — a note that is itself going away cannot keep an attachment alive. Deleting a single note needs only the former; deleting a folder needs the latter, because every note inside it disappears at once. DeleteIfNotUsedParams.shouldProtectIfStillUsed narrows which files that protection covers; a file it rejects is deleted no matter how many notes link to it. Deleting a whole folder of notes uses this to exempt the notes themselves — leaving a dangling link behind is what Obsidian normally does, so keeping every linked-to note would make folder deletion impossible. By default every still-used file is kept. A kept file is stranded: it survives in a folder whose owning note is gone, while the note still referencing it lives elsewhere. DeleteIfNotUsedParams.rescueStillUsedFile is the seam that lets the caller relocate it instead, since where it belongs is the caller’s attachment-path policy, not this function’s. Without that callback the file is simply kept, exactly as before. The actual removal goes through DeleteIfNotUsedParams.deleteAbstractFile when supplied, otherwise through trashSafe. A caller that intercepted a specific deletion primitive passes its unpatched original here, so the user’s chosen semantics (permanent delete vs trash) survive the detour.
EnumDescription
DeleteIfNotUsedResultThe result of deleteIfNotUsed.