mirror of
https://github.com/rust-lang/cargo.git
synced 2025-10-01 11:30:39 +00:00
Document reasoning and report previous error chain
This commit is contained in:
parent
ddc49783ce
commit
0b8c12f5c6
@ -413,13 +413,21 @@ fn _create_dir_all(p: &Path) -> Result<()> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Recursively remove all files and directories at the given directory.
|
/// Equivalent to [`std::fs::remove_dir_all`] with better error messages.
|
||||||
///
|
///
|
||||||
/// This does *not* follow symlinks.
|
/// This does *not* follow symlinks.
|
||||||
pub fn remove_dir_all<P: AsRef<Path>>(p: P) -> Result<()> {
|
pub fn remove_dir_all<P: AsRef<Path>>(p: P) -> Result<()> {
|
||||||
_remove_dir_all(p.as_ref()).or_else(|_| {
|
_remove_dir_all(p.as_ref()).or_else(|prev_err| {
|
||||||
fs::remove_dir_all(p.as_ref())
|
// `std::fs::remove_dir_all` is highly specialized for different platforms
|
||||||
.with_context(|| format!("failed to remove directory `{}`", p.as_ref().display()))
|
// and may be more reliable than a simple walk. We try the walk first in
|
||||||
|
// order to report more detailed errors.
|
||||||
|
fs::remove_dir_all(p.as_ref()).with_context(|| {
|
||||||
|
format!(
|
||||||
|
"failed to remove directory `{}` \n\n---\nPrevious error: {:?}\n---",
|
||||||
|
p.as_ref().display(),
|
||||||
|
prev_err
|
||||||
|
)
|
||||||
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -297,6 +297,7 @@ fn rm_rf(path: &Path, config: &Config, progress: &mut dyn CleaningProgressBar) -
|
|||||||
let entry = entry?;
|
let entry = entry?;
|
||||||
progress.on_clean()?;
|
progress.on_clean()?;
|
||||||
if entry.file_type().is_dir() {
|
if entry.file_type().is_dir() {
|
||||||
|
// `remove_dir_all` is used here due to https://github.com/rust-lang/cargo/issues/11441
|
||||||
paths::remove_dir_all(entry.path())
|
paths::remove_dir_all(entry.path())
|
||||||
.with_context(|| "could not remove build directory")?;
|
.with_context(|| "could not remove build directory")?;
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user