Skip to content

Commit b6ee6bc

Browse files
committed
std::fs::remove_dir_all fails on files
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.
1 parent 717f5df commit b6ee6bc

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

library/std/src/fs.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2804,8 +2804,10 @@ pub fn remove_dir<P: AsRef<Path>>(path: P) -> io::Result<()> {
28042804
///
28052805
/// See [`fs::remove_file`] and [`fs::remove_dir`].
28062806
///
2807-
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root path.
2807+
/// `remove_dir_all` will fail if `remove_dir` or `remove_file` fail on any constituent paths, including the root `path`.
28082808
/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent.
2809+
///
2810+
/// Additionally, `remove_dir_all` will also fail if the `path` is not a directory.
28092811
///
28102812
/// Consider ignoring the error if validating the removal is not required for your use case.
28112813
///

0 commit comments

Comments
 (0)