Skip to content

Commit 280f13b

Browse files
committed
fix: do not lock accounts.toml on iOS
This results in 0xdead10cc crashes on suspend. iOS itself ensures that multiple instances of Delta Chat are not running.
1 parent a96b44a commit 280f13b

File tree

1 file changed

+38
-20
lines changed

1 file changed

+38
-20
lines changed

src/accounts.rs

Lines changed: 38 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -8,11 +8,14 @@ use anyhow::{ensure, Context as _, Result};
88
use serde::{Deserialize, Serialize};
99
use tokio::fs;
1010
use tokio::io::AsyncWriteExt;
11-
use tokio::sync::oneshot;
1211
use tokio::task::JoinHandle;
13-
use tokio::time::{sleep, Duration};
1412
use uuid::Uuid;
1513

14+
#[cfg(not(target_os = "ios"))]
15+
use tokio::sync::oneshot;
16+
#[cfg(not(target_os = "ios"))]
17+
use tokio::time::{sleep, Duration};
18+
1619
use crate::context::Context;
1720
use crate::events::{Event, EventEmitter, EventType, Events};
1821
use crate::stock_str::StockStrings;
@@ -303,6 +306,7 @@ impl Accounts {
303306
const CONFIG_NAME: &str = "accounts.toml";
304307

305308
/// Lockfile name.
309+
#[cfg(not(target_os = "ios"))]
306310
const LOCKFILE_NAME: &str = "accounts.lock";
307311

308312
/// Database file name.
@@ -338,22 +342,16 @@ impl Drop for Config {
338342
}
339343

340344
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<()>>>> {
357355
let lockfile = dir.join(LOCKFILE_NAME);
358356
let mut lock = fd_lock::RwLock::new(fs::File::create(lockfile).await?);
359357
let (locked_tx, locked_rx) = oneshot::channel();
@@ -384,12 +382,32 @@ impl Config {
384382
rx.await?;
385383
Ok(())
386384
});
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?;
387406
let cfg = Self {
388407
file,
389408
inner,
390-
lock_task: Some(lock_task),
409+
lock_task,
391410
};
392-
locked_rx.await?;
393411
Ok(cfg)
394412
}
395413

0 commit comments

Comments
 (0)