Skip to content

Commit f136449

Browse files
fixups
1 parent 217739e commit f136449

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+713
-702
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ on:
1010

1111
env:
1212
RUSTFLAGS: -Dwarnings
13-
13+
1414
jobs:
1515

1616
fmt:

Cargo.lock

Lines changed: 1 addition & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ rust-version = "1.56"
99
[profile.dev]
1010
debug = 0
1111
panic = 'abort'
12+
opt-level = 1
1213

1314
[profile.release]
1415
lto = true
@@ -23,7 +24,7 @@ async-imap = { git = "https://github.com/async-email/async-imap", branch = "runt
2324
async-native-tls = { version = "0.4", default-features = false, features = ["runtime-tokio"] }
2425
async-smtp = { git = "https://github.com/async-email/async-smtp", branch="tokio", default-features = false, features = ["smtp-transport", "socks5", "runtime-tokio"] }
2526
trust-dns-resolver = "0.21"
26-
tokio = { version = "1", features = ["full"] }
27+
tokio = { version = "1", features = ["fs", "rt-multi-thread", "macros"] }
2728
tokio-tar = { version = "0.3" } # TODO: integrate tokio into async-tar
2829
backtrace = "0.3"
2930
base64 = "0.13"

deltachat-ffi/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@ libc = "0.2"
2020
human-panic = "1"
2121
num-traits = "0.2"
2222
serde_json = "1.0"
23-
tokio = { version = "1", features = ["full"] }
23+
tokio = { version = "1", features = ["rt-multi-thread"] }
2424
anyhow = "1"
2525
thiserror = "1"
2626
rand = "0.7"
27-
lazy_static = "1.4.0"
27+
once_cell = "1.12.0"
2828

2929
[features]
3030
default = ["vendored"]

deltachat-ffi/src/lib.rs

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ use std::time::{Duration, SystemTime};
2424
use anyhow::Context as _;
2525
use deltachat::qr_code_generator::get_securejoin_qr_svg;
2626
use num_traits::{FromPrimitive, ToPrimitive};
27+
use once_cell::sync::Lazy;
2728
use rand::Rng;
2829
use tokio::runtime::Runtime;
2930
use tokio::sync::RwLock;
@@ -63,9 +64,7 @@ use deltachat::chatlist::Chatlist;
6364
/// Struct representing the deltachat context.
6465
pub type dc_context_t = Context;
6566

66-
lazy_static::lazy_static! {
67-
static ref RT: Runtime = Runtime::new().expect("unable to create tokio runtime");
68-
}
67+
static RT: Lazy<Runtime> = Lazy::new(|| Runtime::new().expect("unable to create tokio runtime"));
6968

7069
fn block_on<T>(fut: T) -> T::Output
7170
where
@@ -4429,17 +4428,12 @@ pub unsafe extern "C" fn dc_accounts_event_emitter_unref(
44294428
pub unsafe extern "C" fn dc_accounts_get_next_event(
44304429
emitter: *mut dc_accounts_event_emitter_t,
44314430
) -> *mut dc_event_t {
4432-
let _guard = RT.enter();
44334431
if emitter.is_null() {
44344432
eprintln!("ignoring careless call to dc_accounts_get_next_event()");
44354433
return ptr::null_mut();
44364434
}
44374435
let emitter = &mut *emitter;
4438-
block_on(async move {
4439-
emitter
4440-
.recv()
4441-
.await
4442-
.map(|ev| Box::into_raw(Box::new(ev)))
4443-
.unwrap_or_else(ptr::null_mut)
4444-
})
4436+
block_on(emitter.recv())
4437+
.map(|ev| Box::into_raw(Box::new(ev)))
4438+
.unwrap_or_else(ptr::null_mut)
44454439
}

examples/repl/cmdline.rs

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ extern crate dirs;
22

33
use std::path::Path;
44
use std::str::FromStr;
5+
use std::time::{Duration, SystemTime};
56

67
use anyhow::{bail, ensure, Result};
78
use deltachat::chat::{
@@ -22,8 +23,7 @@ use deltachat::peerstate::*;
2223
use deltachat::qr::*;
2324
use deltachat::sql;
2425
use deltachat::{config, provider};
25-
use std::fs;
26-
use std::time::{Duration, SystemTime};
26+
use tokio::fs;
2727

2828
/// Reset database tables.
2929
/// Argument is a bitmask, executing single or multiple actions in one call.
@@ -135,17 +135,13 @@ async fn poke_spec(context: &Context, spec: Option<&str>) -> bool {
135135
} else {
136136
/* import a directory */
137137
let dir_name = std::path::Path::new(&real_spec);
138-
let dir = std::fs::read_dir(dir_name);
138+
let dir = fs::read_dir(dir_name).await;
139139
if dir.is_err() {
140140
error!(context, "Import: Cannot open directory \"{}\".", &real_spec,);
141141
return false;
142142
} else {
143-
let dir = dir.unwrap();
144-
for entry in dir {
145-
if entry.is_err() {
146-
break;
147-
}
148-
let entry = entry.unwrap();
143+
let mut dir = dir.unwrap();
144+
while let Ok(Some(entry)) = dir.next_entry().await {
149145
let name_f = entry.file_name();
150146
let name = name_f.to_string_lossy();
151147
if name.ends_with(".eml") {
@@ -492,7 +488,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
492488
let setup_code = create_setup_code(&context);
493489
let file_name = blobdir.join("autocrypt-setup-message.html");
494490
let file_content = render_setup_file(&context, &setup_code).await?;
495-
tokio::fs::write(&file_name, file_content).await?;
491+
fs::write(&file_name, file_content).await?;
496492
println!(
497493
"Setup message written to: {}\nSetup code: {}",
498494
file_name.display(),
@@ -532,7 +528,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
532528
.join("connectivity.html");
533529
match context.get_connectivity_html().await {
534530
Ok(html) => {
535-
fs::write(&file, html)?;
531+
fs::write(&file, html).await?;
536532
println!("Report written to: {:#?}", file);
537533
}
538534
Err(err) => {
@@ -892,7 +888,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
892888
ensure!(sel_chat.is_some(), "No chat selected.");
893889
ensure!(!arg1.is_empty(), "No html-file given.");
894890
let path: &Path = arg1.as_ref();
895-
let html = &*fs::read(&path)?;
891+
let html = &*fs::read(&path).await?;
896892
let html = String::from_utf8_lossy(html);
897893

898894
let mut msg = Message::new(Viewtype::Text);
@@ -1079,7 +1075,7 @@ pub async fn cmdline(context: Context, line: &str, chat_id: &mut ChatId) -> Resu
10791075
.unwrap_or_default()
10801076
.join(format!("msg-{}.html", id.to_u32()));
10811077
let html = id.get_html(&context).await?.unwrap_or_default();
1082-
fs::write(&file, html)?;
1078+
fs::write(&file, html).await?;
10831079
println!("HTML written to: {:#?}", file);
10841080
}
10851081
"listfresh" => {

examples/repl/main.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use deltachat::chat::ChatId;
1818
use deltachat::config;
1919
use deltachat::context::*;
2020
use deltachat::oauth2::*;
21+
use deltachat::qr_code_generator::get_securejoin_qr_svg;
2122
use deltachat::securejoin::*;
2223
use deltachat::{EventType, Events};
2324
use log::{error, info, warn};
@@ -30,12 +31,11 @@ use rustyline::validate::Validator;
3031
use rustyline::{
3132
Cmd, CompletionType, Config, Context as RustyContext, EditMode, Editor, Helper, KeyEvent,
3233
};
34+
use tokio::fs;
3335
use tokio::runtime::Handle;
3436

3537
mod cmdline;
3638
use self::cmdline::*;
37-
use deltachat::qr_code_generator::get_securejoin_qr_svg;
38-
use std::fs;
3939

4040
/// Event Handler
4141
fn receive_event(event: EventType) {
@@ -446,7 +446,7 @@ async fn handle_cmd(
446446
let file = dirs::home_dir().unwrap_or_default().join("qr.svg");
447447
match get_securejoin_qr_svg(&ctx, group).await {
448448
Ok(svg) => {
449-
fs::write(&file, svg)?;
449+
fs::write(&file, svg).await?;
450450
println!("QR code svg written to: {:#?}", file);
451451
}
452452
Err(err) => {

src/accounts.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl AccountConfig {
447447
mod tests {
448448
use super::*;
449449

450-
#[tokio::test]
450+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
451451
async fn test_account_new_open() {
452452
let dir = tempfile::tempdir().unwrap();
453453
let p: PathBuf = dir.path().join("accounts1");
@@ -465,7 +465,7 @@ mod tests {
465465
assert_eq!(accounts1.accounts.len(), accounts2.accounts.len());
466466
}
467467

468-
#[tokio::test]
468+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
469469
async fn test_account_new_add_remove() {
470470
let dir = tempfile::tempdir().unwrap();
471471
let p: PathBuf = dir.path().join("accounts");
@@ -492,7 +492,7 @@ mod tests {
492492
assert_eq!(accounts.accounts.len(), 1);
493493
}
494494

495-
#[tokio::test]
495+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
496496
async fn test_accounts_remove_last() -> Result<()> {
497497
let dir = tempfile::tempdir()?;
498498
let p: PathBuf = dir.path().join("accounts");
@@ -513,7 +513,7 @@ mod tests {
513513
Ok(())
514514
}
515515

516-
#[tokio::test]
516+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
517517
async fn test_migrate_account() {
518518
let dir = tempfile::tempdir().unwrap();
519519
let p: PathBuf = dir.path().join("accounts");
@@ -550,7 +550,7 @@ mod tests {
550550
}
551551

552552
/// Tests that accounts are sorted by ID.
553-
#[tokio::test]
553+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
554554
async fn test_accounts_sorted() {
555555
let dir = tempfile::tempdir().unwrap();
556556
let p: PathBuf = dir.path().join("accounts");
@@ -568,7 +568,7 @@ mod tests {
568568
}
569569
}
570570

571-
#[tokio::test]
571+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
572572
async fn test_accounts_ids_unique_increasing_and_persisted() -> Result<()> {
573573
let dir = tempfile::tempdir()?;
574574
let p: PathBuf = dir.path().join("accounts");
@@ -650,7 +650,7 @@ mod tests {
650650
Ok(())
651651
}
652652

653-
#[tokio::test]
653+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
654654
async fn test_no_accounts_event_emitter() -> Result<()> {
655655
let dir = tempfile::tempdir().unwrap();
656656
let p: PathBuf = dir.path().join("accounts");
@@ -676,7 +676,7 @@ mod tests {
676676
Ok(())
677677
}
678678

679-
#[tokio::test]
679+
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
680680
async fn test_encrypted_account() -> Result<()> {
681681
let dir = tempfile::tempdir().context("failed to create tempdir")?;
682682
let p: PathBuf = dir.path().join("accounts");

0 commit comments

Comments
 (0)