Crate rmr

Crate rmr 

Source
Expand description

Remove files or directories passed as CLI args (recursive for dirs).

Strips trailing metadata suffix beginning at the first ‘:’ in each argument (colon and suffix removed) before deletion. Useful when piping annotated paths (e.g. from linters or search tools emitting path:line:col).

§Arguments

  • <paths...> One or more filesystem paths (files, symlinks, or directories). Optional trailing :... suffix is removed.

§Returns

  • Exit code 0 if all provided paths were deleted successfully (or no paths given).
  • Exit code 1 if any path failed to delete or did not exist.

§Errors

§Rationale

  • Eliminates need for ad-hoc shell loops to mass-delete mixed file & directory sets while handling tool:line:col style suffixes.
  • Colorized error reporting highlights problematic paths quickly.

§Performance

  • One reverse byte scan per argument to locate last ‘:’ (no allocation).
  • Single symlink_metadata call per path (branches on std::fs::FileType), minimizing metadata syscalls.
  • Sequential deletions avoid contention; for huge argument lists, parallelism could help but increases complexity (ordering, error aggregation).

§Future Work

  • Add --dry-run flag for previewing deletions.
  • Add parallel deletion (configurable) for large batches.
  • Accept glob patterns expanded internally (on platforms without shell globbing).

Functions§

before_first_colon 🔒
Strips suffix beginning at first ‘:’; returns subslice before colon.
main 🔒
Remove files or directories passed as CLI args (recursive for dirs).
process 🔒
Deletes one path after stripping the first ‘:’ suffix segment.