1
1
//! # Account manager module.
2
2
3
3
use std:: collections:: BTreeMap ;
4
- use std:: future:: Future ;
5
4
use std:: path:: { Path , PathBuf } ;
6
5
7
6
use anyhow:: { ensure, Context as _, Result } ;
@@ -171,7 +170,7 @@ impl Accounts {
171
170
if let Some ( cfg) = self . config . get_account ( id) {
172
171
let account_path = self . dir . join ( cfg. dir ) ;
173
172
174
- try_many_times ( || fs:: remove_dir_all ( & account_path) )
173
+ fs:: remove_dir_all ( & account_path)
175
174
. await
176
175
. context ( "failed to remove account data" ) ?;
177
176
}
@@ -207,10 +206,10 @@ impl Accounts {
207
206
fs:: create_dir_all ( self . dir . join ( & account_config. dir ) )
208
207
. await
209
208
. context ( "failed to create dir" ) ?;
210
- try_many_times ( || fs:: rename ( & dbfile, & new_dbfile) )
209
+ fs:: rename ( & dbfile, & new_dbfile)
211
210
. await
212
211
. context ( "failed to rename dbfile" ) ?;
213
- try_many_times ( || fs:: rename ( & blobdir, & new_blobdir) )
212
+ fs:: rename ( & blobdir, & new_blobdir)
214
213
. await
215
214
. context ( "failed to rename blobdir" ) ?;
216
215
if walfile. exists ( ) {
@@ -235,7 +234,7 @@ impl Accounts {
235
234
}
236
235
Err ( err) => {
237
236
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)
239
238
. await
240
239
. context ( "failed to remove account data" ) ?;
241
240
self . config . remove_account ( account_config. id ) . await ?;
@@ -620,37 +619,6 @@ impl Config {
620
619
}
621
620
}
622
621
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
-
654
622
/// Configuration of a single account.
655
623
#[ derive( Serialize , Deserialize , Debug , Clone , PartialEq ) ]
656
624
struct AccountConfig {
0 commit comments