@@ -8,11 +8,14 @@ use anyhow::{ensure, Context as _, Result};
8
8
use serde:: { Deserialize , Serialize } ;
9
9
use tokio:: fs;
10
10
use tokio:: io:: AsyncWriteExt ;
11
- use tokio:: sync:: oneshot;
12
11
use tokio:: task:: JoinHandle ;
13
- use tokio:: time:: { sleep, Duration } ;
14
12
use uuid:: Uuid ;
15
13
14
+ #[ cfg( not( target_os = "ios" ) ) ]
15
+ use tokio:: sync:: oneshot;
16
+ #[ cfg( not( target_os = "ios" ) ) ]
17
+ use tokio:: time:: { sleep, Duration } ;
18
+
16
19
use crate :: context:: Context ;
17
20
use crate :: events:: { Event , EventEmitter , EventType , Events } ;
18
21
use crate :: stock_str:: StockStrings ;
@@ -303,6 +306,7 @@ impl Accounts {
303
306
const CONFIG_NAME : & str = "accounts.toml" ;
304
307
305
308
/// Lockfile name.
309
+ #[ cfg( not( target_os = "ios" ) ) ]
306
310
const LOCKFILE_NAME : & str = "accounts.lock" ;
307
311
308
312
/// Database file name.
@@ -338,22 +342,16 @@ impl Drop for Config {
338
342
}
339
343
340
344
impl Config {
341
- /// Creates a new Config for `file`, but doesn't open/sync it.
342
- async fn new_nosync ( file : PathBuf , lock : bool ) -> Result < Self > {
343
- let dir = file. parent ( ) . context ( "Cannot get config file directory" ) ?;
344
- let inner = InnerConfig {
345
- accounts : Vec :: new ( ) ,
346
- selected_account : 0 ,
347
- next_id : 1 ,
348
- } ;
349
- if !lock {
350
- let cfg = Self {
351
- file,
352
- inner,
353
- lock_task : None ,
354
- } ;
355
- return Ok ( cfg) ;
356
- }
345
+ #[ cfg( target_os = "ios" ) ]
346
+ async fn create_lock_task ( _dir : PathBuf ) -> Result < Option < JoinHandle < anyhow:: Result < ( ) > > > > {
347
+ // Do not lock accounts.toml on iOS.
348
+ // This results in 0xdead10cc crashes on suspend.
349
+ // iOS itself ensures that multiple instances of Delta Chat are not running.
350
+ Ok ( None )
351
+ }
352
+
353
+ #[ cfg( not( target_os = "ios" ) ) ]
354
+ async fn create_lock_task ( dir : PathBuf ) -> Result < Option < JoinHandle < anyhow:: Result < ( ) > > > > {
357
355
let lockfile = dir. join ( LOCKFILE_NAME ) ;
358
356
let mut lock = fd_lock:: RwLock :: new ( fs:: File :: create ( lockfile) . await ?) ;
359
357
let ( locked_tx, locked_rx) = oneshot:: channel ( ) ;
@@ -384,12 +382,32 @@ impl Config {
384
382
rx. await ?;
385
383
Ok ( ( ) )
386
384
} ) ;
385
+ locked_rx. await ?;
386
+ Ok ( Some ( lock_task) )
387
+ }
388
+
389
+ /// Creates a new Config for `file`, but doesn't open/sync it.
390
+ async fn new_nosync ( file : PathBuf , lock : bool ) -> Result < Self > {
391
+ let dir = file. parent ( ) . context ( "Cannot get config file directory" ) ?;
392
+ let inner = InnerConfig {
393
+ accounts : Vec :: new ( ) ,
394
+ selected_account : 0 ,
395
+ next_id : 1 ,
396
+ } ;
397
+ if !lock {
398
+ let cfg = Self {
399
+ file,
400
+ inner,
401
+ lock_task : None ,
402
+ } ;
403
+ return Ok ( cfg) ;
404
+ }
405
+ let lock_task = Self :: create_lock_task ( dir. to_path_buf ( ) ) . await ?;
387
406
let cfg = Self {
388
407
file,
389
408
inner,
390
- lock_task : Some ( lock_task ) ,
409
+ lock_task,
391
410
} ;
392
- locked_rx. await ?;
393
411
Ok ( cfg)
394
412
}
395
413
0 commit comments