Rust's standard library provides std::fs::remove_dir_all("/some/dir"), in C++ you will find the very similar std::filesystem::remove_all("/some/dir")
As you might anticipate, these functions get rid of the directory /some/dir if necessary deleting sub-directories and files recursively in order to achieve that.
They both explain that they won't delete other things, even if there's a symlink in /some/dir or some child that points to those outside things, the symlink gets deleted but not the thing it pointed to.
What kind of terrible unsafety was discovered in CVE-2022-21658?
Until Rust 1.58.1 you could exploit a TOCTOU race condition to blow away other people's stuff using symlinks when they made this call.
And where is the CVE for the same bug in C++? There isn't one. C++ standards people argued that the C++ standard already actually says that none of their filesystem API is safe to use if you have a "concurrent environment" in which such races are possible. Standard C++ programs are only intended to run on a machine where they have exclusive control over the entire system for the entire length of their runtime and so when your C++ program deletes files you thought it couldn't delete that was actually your fault for not being familiar with every caveat and ruling in the entire C++ standard.
What should you do about that? I believe the answer is obvious: Use Rust