๐ Overview
obliterate is a Linux-only Rust crate designed to aggressively and safely
remove files and directories โ even in scenarios where traditional tools fail.
It handles edge cases like 000 permissions, nested mount points, and deeply
recursive trees without stack overflows.
Unlike traditional approaches, this crate:
- Fixes permissions automatically before deletion;
- Detects and lazily unmounts nested mount points;
- Avoids dangerous path patterns like
..; - Uses controlled recursion with stack growth protection;
๐ Features
-
๐ Handles
000permissions
removes trees thatstd::fs::remove_dir_allcannot. -
๐งฉ Mount-point aware
lazily unmounts nested filesystems before deleting. -
๐งฑ Stack-safe recursion
usesstackerto safely handle deeply nested trees. -
๐ก๏ธ Basic safety guards
prevents invalid paths like... -
๐ฆ Structured errors
clear error types for invalid targets, I/O failures, and unmount issues. -
๐ง Linux-only
relies on/proc/self/mountinfoandumount2.
๐ Usage
This section demonstrates how to integrate and use obliterate in your Rust
project. The crate provides two main entry points:
removeโ strict removal (fails if the path does not exist)ensure_removedโ forgiving removal (behaves likerm -rf)
Add the dependency to your Cargo.toml:
[]
= "1.0"
Then use it in your code:
use ;
// Strict removal (fails if not found)
remove?;
// Idempotent removal (like rm -rf)
ensure_removed?;
match remove
๐ก When to use each function
- Use
removewhen you expect the path to exist and want strict error handling. - Use
ensure_removedwhen you want idempotent cleanup, especially in build scripts, CI pipelines, or temporary directory management.
Both functions guarantee safe, race-resistant removal using file-descriptor-based operations under the hood.
โ๏ธ How it works
๐ Permission handling
Before deletion, the crate ensures the current process has sufficient
permissions by setting mode 0o700 when necessary. std::fs::remove_dir_all fails
on directories with 000 permissions because the kernel checks execute permission
on the directory before allowing iteration.
๐งท Mount-point handling
Before touching any directory, obliterate reads /proc/self/mountinfo and
collects every mount-point nested inside the target tree. They are unmounted
deepest-first using a three-tier strategy:
umount2(MNT_DETACH)via libcfusermount3 -u -zfusermount -u -z
Mounts are processed deepest-first to avoid dependency issues. If unmounting fails, an error is returned and deletion is aborted.
๐งต Recursive removal
The crate recursively deletes files and directories while:
- Fixing permissions
- Avoiding stack overflow via
stacker - Handling both files and directories correctly
โ Error variants
๐งช Notes
Some unmount operations may require elevated privileges (CAP_SYS_ADMIN).
๐ MIT License
This project is licensed under the MIT License.