diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-04-27 21:34:13 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-04-27 21:34:13 +0200 |
| commit | e13b7f73c31f42d2e8cce1a23d599ee9080d3895 (patch) | |
| tree | 4280020fa2af8c3e42160ac445105718be53f0be | |
| parent | 901fdb3b04375e3456b5cf771f86ecca8d6c1917 (diff) | |
| parent | d5d2785c86a70fba65e9baa862a54be22b3b786c (diff) | |
| download | rust-e13b7f73c31f42d2e8cce1a23d599ee9080d3895.tar.gz rust-e13b7f73c31f42d2e8cce1a23d599ee9080d3895.zip | |
Rollup merge of #105745 - philpax:patch-1, r=jyn514
docs(std): clarify remove_dir_all errors When using `remove_dir_all`, I assumed that the function was idempotent and that I could always call it to remove a directory if it existed. That's not the case and it bit me in production, so I figured I'd submit this to clarify the docs.
| -rw-r--r-- | library/std/src/fs.rs | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/library/std/src/fs.rs b/library/std/src/fs.rs index 42a68496fc4..30e553f285b 100644 --- a/library/std/src/fs.rs +++ b/library/std/src/fs.rs @@ -2284,6 +2284,11 @@ 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. +/// As a result, the directory you are deleting must exist, meaning that this function is not idempotent. +/// +/// Consider ignoring the error if validating the removal is not required for your use case. +/// /// [`fs::remove_file`]: remove_file /// [`fs::remove_dir`]: remove_dir /// |
