Skip to content

Commit

Permalink
fix: retry remove_dir_all 3 times in ensure_clean (#320)
Browse files Browse the repository at this point in the history
Workaround of the #319
  • Loading branch information
wangl-cc authored Sep 6, 2024
1 parent 6e84d11 commit dcea6df
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion maa-cli/src/dirs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -383,7 +383,20 @@ impl Ensure for &Path {

fn ensure_clean(self) -> Result<Self, Self::Error> {
if self.exists() {
remove_dir_all(self)?;
let mut ret = remove_dir_all(self);
for i in 1..=3 {
if let Err(err) = &ret {
log::warn!(
"Failed to remove dir {} due to {err}, retry {i} times",
self.display()
);
std::thread::sleep(std::time::Duration::from_secs(1));
ret = remove_dir_all(self);
} else {
break;
}
}
ret?;
} else if let Some(parent) = self.parent() {
parent.ensure()?;
}
Expand Down Expand Up @@ -429,6 +442,8 @@ where
/// # Panics
///
/// Panics if the given str is a string containing path separator.
///
/// This function only called at compile time, so it's dead code in release build.
#[allow(dead_code)]
fn ensure_name(name: &str) -> &str {
assert!(
Expand Down

0 comments on commit dcea6df

Please sign in to comment.