diff options
| author | bors <bors@rust-lang.org> | 2024-08-23 08:31:26 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2024-08-23 08:31:26 +0000 |
| commit | c8b14ba7b6777dfbfb64a02d7bbe867a54dddf2a (patch) | |
| tree | 7e4bbc1407c3d14d35dc1e424a61654cc1f648a8 /library/std/src/sys_common | |
| parent | b5723af3457b9cd3795eeb97e9af2d34964854f2 (diff) | |
| parent | 6c2ee6fe77b4db7b1b523a8a514d67d68855eeb1 (diff) | |
| download | rust-c8b14ba7b6777dfbfb64a02d7bbe867a54dddf2a.tar.gz rust-c8b14ba7b6777dfbfb64a02d7bbe867a54dddf2a.zip | |
Auto merge of #129443 - matthiaskrgr:rollup-tbgdj0p, r=matthiaskrgr
Rollup of 8 pull requests Successful merges: - #127623 (fix: fs::remove_dir_all: treat internal ENOENT as success) - #128876 (Ship MinGW-w64 runtime DLLs along with `rust-lld.exe` for `-pc-windows-gnu` targets) - #129055 (Migrate `x86_64-fortanix-unknown-sgx-lvi` `run-make` test to rmake) - #129386 (Use a LocalDefId in ResolvedArg.) - #129400 (Update `compiler_builtins` to `0.1.120`) - #129414 (Fix extern crates not being hidden with `doc(hidden)`) - #129417 (Don't trigger refinement lint if predicates reference errors) - #129433 (Fix a missing import in a doc in run-make-support) r? `@ghost` `@rustbot` modify labels: rollup
Diffstat (limited to 'library/std/src/sys_common')
| -rw-r--r-- | library/std/src/sys_common/fs.rs | 21 | ||||
| -rw-r--r-- | library/std/src/sys_common/mod.rs | 8 |
2 files changed, 23 insertions, 6 deletions
diff --git a/library/std/src/sys_common/fs.rs b/library/std/src/sys_common/fs.rs index acb6713cf1b..a25a7244660 100644 --- a/library/std/src/sys_common/fs.rs +++ b/library/std/src/sys_common/fs.rs @@ -3,6 +3,7 @@ use crate::fs; use crate::io::{self, Error, ErrorKind}; use crate::path::Path; +use crate::sys_common::ignore_notfound; pub(crate) const NOT_FILE_ERROR: Error = io::const_io_error!( ErrorKind::InvalidInput, @@ -32,14 +33,22 @@ pub fn remove_dir_all(path: &Path) -> io::Result<()> { fn remove_dir_all_recursive(path: &Path) -> io::Result<()> { for child in fs::read_dir(path)? { - let child = child?; - if child.file_type()?.is_dir() { - remove_dir_all_recursive(&child.path())?; - } else { - fs::remove_file(&child.path())?; + let result: io::Result<()> = try { + let child = child?; + if child.file_type()?.is_dir() { + remove_dir_all_recursive(&child.path())?; + } else { + fs::remove_file(&child.path())?; + } + }; + // ignore internal NotFound errors to prevent race conditions + if let Err(err) = &result + && err.kind() != io::ErrorKind::NotFound + { + return result; } } - fs::remove_dir(path) + ignore_notfound(fs::remove_dir(path)) } pub fn exists(path: &Path) -> io::Result<bool> { diff --git a/library/std/src/sys_common/mod.rs b/library/std/src/sys_common/mod.rs index 60ee405ecaa..1c884f107be 100644 --- a/library/std/src/sys_common/mod.rs +++ b/library/std/src/sys_common/mod.rs @@ -80,3 +80,11 @@ pub fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 { // r < denom, so (denom*numer) is the upper bound of (r*numer) q * numer + r * numer / denom } + +pub fn ignore_notfound<T>(result: crate::io::Result<T>) -> crate::io::Result<()> { + match result { + Err(err) if err.kind() == crate::io::ErrorKind::NotFound => Ok(()), + Ok(_) => Ok(()), + Err(err) => Err(err), + } +} |
