Skip to content

Commit 0cdf9b8

Browse files
committed
debug: remove try_many_times
Attempt to reproduce <#5809> in CI.
1 parent 4ec5d12 commit 0cdf9b8

File tree

1 file changed

+4
-36
lines changed

1 file changed

+4
-36
lines changed

src/accounts.rs

Lines changed: 4 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
//! # Account manager module.
22
33
use std::collections::BTreeMap;
4-
use std::future::Future;
54
use std::path::{Path, PathBuf};
65

76
use anyhow::{ensure, Context as _, Result};
@@ -171,7 +170,7 @@ impl Accounts {
171170
if let Some(cfg) = self.config.get_account(id) {
172171
let account_path = self.dir.join(cfg.dir);
173172

174-
try_many_times(|| fs::remove_dir_all(&account_path))
173+
fs::remove_dir_all(&account_path)
175174
.await
176175
.context("failed to remove account data")?;
177176
}
@@ -207,10 +206,10 @@ impl Accounts {
207206
fs::create_dir_all(self.dir.join(&account_config.dir))
208207
.await
209208
.context("failed to create dir")?;
210-
try_many_times(|| fs::rename(&dbfile, &new_dbfile))
209+
fs::rename(&dbfile, &new_dbfile)
211210
.await
212211
.context("failed to rename dbfile")?;
213-
try_many_times(|| fs::rename(&blobdir, &new_blobdir))
212+
fs::rename(&blobdir, &new_blobdir)
214213
.await
215214
.context("failed to rename blobdir")?;
216215
if walfile.exists() {
@@ -235,7 +234,7 @@ impl Accounts {
235234
}
236235
Err(err) => {
237236
let account_path = std::path::PathBuf::from(&account_config.dir);
238-
try_many_times(|| fs::remove_dir_all(&account_path))
237+
fs::remove_dir_all(&account_path)
239238
.await
240239
.context("failed to remove account data")?;
241240
self.config.remove_account(account_config.id).await?;
@@ -620,37 +619,6 @@ impl Config {
620619
}
621620
}
622621

623-
/// Spend up to 1 minute trying to do the operation.
624-
///
625-
/// Even if Delta Chat itself does not hold the file lock,
626-
/// there may be other processes such as antivirus,
627-
/// or the filesystem may be network-mounted.
628-
///
629-
/// Without this workaround removing account may fail on Windows with an error
630-
/// "The process cannot access the file because it is being used by another process. (os error 32)".
631-
async fn try_many_times<F, Fut, T>(f: F) -> std::result::Result<(), T>
632-
where
633-
F: Fn() -> Fut,
634-
Fut: Future<Output = std::result::Result<(), T>>,
635-
{
636-
let mut counter = 0;
637-
loop {
638-
counter += 1;
639-
640-
if let Err(err) = f().await {
641-
if counter > 60 {
642-
return Err(err);
643-
}
644-
645-
// Wait 1 second and try again.
646-
tokio::time::sleep(std::time::Duration::from_millis(1000)).await;
647-
} else {
648-
break;
649-
}
650-
}
651-
Ok(())
652-
}
653-
654622
/// Configuration of a single account.
655623
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
656624
struct AccountConfig {

0 commit comments

Comments
 (0)