From b2c5560e302d558349ec6c57e87247ec200bd50e Mon Sep 17 00:00:00 2001 From: link2xt Date: Sat, 18 Feb 2023 01:57:19 +0000 Subject: [PATCH] Remove `try_many_times` r2d2 bug workaround --- src/accounts.rs | 36 ++++-------------------------------- 1 file changed, 4 insertions(+), 32 deletions(-) diff --git a/src/accounts.rs b/src/accounts.rs index e01cc49c2..8ec3a34c8 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -1,7 +1,6 @@ //! # Account manager module. use std::collections::BTreeMap; -use std::future::Future; use std::path::{Path, PathBuf}; use anyhow::{ensure, Context as _, Result}; @@ -151,7 +150,7 @@ impl Accounts { if let Some(cfg) = self.config.get_account(id) { let account_path = self.dir.join(cfg.dir); - try_many_times(|| fs::remove_dir_all(&account_path)) + fs::remove_dir_all(&account_path) .await .context("failed to remove account data")?; } @@ -187,10 +186,10 @@ impl Accounts { fs::create_dir_all(self.dir.join(&account_config.dir)) .await .context("failed to create dir")?; - try_many_times(|| fs::rename(&dbfile, &new_dbfile)) + fs::rename(&dbfile, &new_dbfile) .await .context("failed to rename dbfile")?; - try_many_times(|| fs::rename(&blobdir, &new_blobdir)) + fs::rename(&blobdir, &new_blobdir) .await .context("failed to rename blobdir")?; if walfile.exists() { @@ -215,7 +214,7 @@ impl Accounts { } Err(err) => { let account_path = std::path::PathBuf::from(&account_config.dir); - try_many_times(|| fs::remove_dir_all(&account_path)) + fs::remove_dir_all(&account_path) .await .context("failed to remove account data")?; self.config.remove_account(account_config.id).await?; @@ -472,33 +471,6 @@ impl Config { } } -/// Spend up to 1 minute trying to do the operation. -/// -/// Files may remain locked up to 30 seconds due to r2d2 bug: -/// -async fn try_many_times(f: F) -> std::result::Result<(), T> -where - F: Fn() -> Fut, - Fut: Future>, -{ - let mut counter = 0; - loop { - counter += 1; - - if let Err(err) = f().await { - if counter > 60 { - return Err(err); - } - - // Wait 1 second and try again. - tokio::time::sleep(std::time::Duration::from_millis(1000)).await; - } else { - break; - } - } - Ok(()) -} - /// Configuration of a single account. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] struct AccountConfig {