Skip to content

Commit

Permalink
std::fs::remove_dir_all fails on files
Browse files Browse the repository at this point in the history
This is explicitly mentioned for std::fs::remove_file.

It is more likely for a slightly lazy programmer to believe that
removing a file would work and that they do not have to distinguish
between directories (with contents) and files themself, because of the
function's recursive nature and how it distinguishes between files and
directories when removing them.
  • Loading branch information
n0toose committed Nov 21, 2024
1 parent 717f5df commit b6ee6bc
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion library/std/src/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2804,8 +2804,10 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
///
/// See [`fs::remove_file`] and [`fs::remove_dir`].
///
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path.
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root `path`.
/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
///
/// Additionally, `remove_dir_all` will also fail if the `path` is not a directory.
///
/// Consider ignoring the error if validating the removal is not required for your use case.
///
Expand Down

0 comments on commit b6ee6bc

Please sign in to comment.