Function remove_dir_all::ensure_empty_dir
source · pub fn ensure_empty_dir<P: AsRef<Path>>(path: P) -> Result<()>
Expand description
Makes path
an empty directory: if it does not exist, it is created it as
an empty directory (as if with std::fs::create_dir
); if it does exist, its
contents are deleted (as if with remove_dir_contents
).
It is an error if path
exists but is not a directory, including a symlink
to a directory.
This is subject to file system races: a privileged process could be attacked
by replacing parent directories of the supplied path with a link (e.g. to
/etc). Consider using RemoveDir::remove_dir_contents
instead.