diff --git a/deltachat-ffi/src/lib.rs b/deltachat-ffi/src/lib.rs index e9d7e6162..072930b96 100644 --- a/deltachat-ffi/src/lib.rs +++ b/deltachat-ffi/src/lib.rs @@ -63,7 +63,7 @@ pub type dc_context_t = Context; #[no_mangle] pub unsafe extern "C" fn dc_context_new( - os_name: *const libc::c_char, + _os_name: *const libc::c_char, dbfile: *const libc::c_char, blobdir: *const libc::c_char, ) -> *mut dc_context_t { @@ -74,21 +74,11 @@ pub unsafe extern "C" fn dc_context_new( return ptr::null_mut(); } - let os_name = if os_name.is_null() { - String::from("DcFFI") - } else { - to_string_lossy(os_name) - }; - let ctx = if blobdir.is_null() || *blobdir == 0 { use rand::Rng; // generate random ID as this functionality is not yet available on the C-api. let id = rand::thread_rng().gen(); - block_on(Context::new( - os_name, - as_path(dbfile).to_path_buf().into(), - id, - )) + block_on(Context::new(as_path(dbfile).to_path_buf().into(), id)) } else { eprintln!("blobdir can not be defined explicitly anymore"); return ptr::null_mut(); @@ -3839,7 +3829,7 @@ pub type dc_accounts_t = AccountsWrapper; #[no_mangle] pub unsafe extern "C" fn dc_accounts_new( - os_name: *const libc::c_char, + _os_name: *const libc::c_char, dbfile: *const libc::c_char, ) -> *mut dc_accounts_t { setup_panic!(); @@ -3849,13 +3839,7 @@ pub unsafe extern "C" fn dc_accounts_new( return ptr::null_mut(); } - let os_name = if os_name.is_null() { - String::from("DcFFI") - } else { - to_string_lossy(os_name) - }; - - let accs = block_on(Accounts::new(os_name, as_path(dbfile).to_path_buf().into())); + let accs = block_on(Accounts::new(as_path(dbfile).to_path_buf().into())); match accs { Ok(accs) => Box::into_raw(Box::new(AccountsWrapper::new(accs))), diff --git a/examples/repl/main.rs b/examples/repl/main.rs index 21ac12d0d..22eac2438 100644 --- a/examples/repl/main.rs +++ b/examples/repl/main.rs @@ -297,7 +297,7 @@ async fn start(args: Vec) -> Result<(), Error> { println!("Error: Bad arguments, expected [db-name]."); bail!("No db-name specified"); } - let context = Context::new("CLI".into(), Path::new(&args[1]).to_path_buf(), 0).await?; + let context = Context::new(Path::new(&args[1]).to_path_buf(), 0).await?; let events = context.get_event_emitter(); async_std::task::spawn(async move { diff --git a/examples/simple.rs b/examples/simple.rs index 2aa0ca960..fc875832c 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -36,7 +36,7 @@ async fn main() { let dir = tempdir().unwrap(); let dbfile = dir.path().join("db.sqlite"); log::info!("creating database {:?}", dbfile); - let ctx = Context::new("FakeOs".into(), dbfile.into(), 0) + let ctx = Context::new(dbfile.into(), 0) .await .expect("Failed to create context"); let info = ctx.get_info().await; diff --git a/src/accounts.rs b/src/accounts.rs index 4885c0cab..7cc4d3e48 100644 --- a/src/accounts.rs +++ b/src/accounts.rs @@ -29,21 +29,21 @@ pub struct Accounts { impl Accounts { /// Loads or creates an accounts folder at the given `dir`. - pub async fn new(os_name: String, dir: PathBuf) -> Result { + pub async fn new(dir: PathBuf) -> Result { if !dir.exists().await { - Accounts::create(os_name, &dir).await?; + Accounts::create(&dir).await?; } Accounts::open(dir).await } /// Creates a new default structure. - pub async fn create(os_name: String, dir: &PathBuf) -> Result<()> { + pub async fn create(dir: &PathBuf) -> Result<()> { fs::create_dir_all(dir) .await .context("failed to create folder")?; - Config::new(os_name.clone(), dir).await?; + Config::new(dir).await?; Ok(()) } @@ -106,10 +106,9 @@ impl Accounts { /// Add a new account. pub async fn add_account(&mut self) -> Result { - let os_name = self.config.os_name().await; let account_config = self.config.new_account(&self.dir).await?; - let ctx = Context::new(os_name, account_config.dbfile().into(), account_config.id).await?; + let ctx = Context::new(account_config.dbfile().into(), account_config.id).await?; self.emitter.add_account(&ctx).await?; self.accounts.insert(account_config.id, ctx); @@ -183,13 +182,7 @@ impl Accounts { match res { Ok(_) => { - let ctx = Context::with_blobdir( - self.config.os_name().await, - new_dbfile, - new_blobdir, - account_config.id, - ) - .await?; + let ctx = Context::with_blobdir(new_dbfile, new_blobdir, account_config.id).await?; self.emitter.add_account(&ctx).await?; self.accounts.insert(account_config.id, ctx); Ok(account_config.id) @@ -349,7 +342,6 @@ pub struct Config { /// This is serialized into TOML. #[derive(Serialize, Deserialize, Debug, Clone, PartialEq)] struct InnerConfig { - pub os_name: String, /// The currently selected account. pub selected_account: u32, pub next_id: u32, @@ -357,9 +349,8 @@ struct InnerConfig { } impl Config { - pub async fn new(os_name: String, dir: &PathBuf) -> Result { + pub async fn new(dir: &PathBuf) -> Result { let inner = InnerConfig { - os_name, accounts: Vec::new(), selected_account: 0, next_id: 1, @@ -374,10 +365,6 @@ impl Config { Ok(cfg) } - pub async fn os_name(&self) -> String { - self.inner.os_name.clone() - } - /// Sync the inmemory representation to disk. async fn sync(&self) -> Result<()> { fs::write(&self.file, toml::to_string_pretty(&self.inner)?) @@ -396,12 +383,7 @@ impl Config { pub async fn load_accounts(&self) -> Result> { let mut accounts = BTreeMap::new(); for account_config in &self.inner.accounts { - let ctx = Context::new( - self.inner.os_name.clone(), - account_config.dbfile().into(), - account_config.id, - ) - .await?; + let ctx = Context::new(account_config.dbfile().into(), account_config.id).await?; accounts.insert(account_config.id, ctx); } @@ -498,7 +480,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let p: PathBuf = dir.path().join("accounts1").into(); - let mut accounts1 = Accounts::new("my_os".into(), p.clone()).await.unwrap(); + let mut accounts1 = Accounts::new(p.clone()).await.unwrap(); accounts1.add_account().await.unwrap(); let accounts2 = Accounts::open(p).await.unwrap(); @@ -516,7 +498,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let p: PathBuf = dir.path().join("accounts").into(); - let mut accounts = Accounts::new("my_os".into(), p.clone()).await.unwrap(); + let mut accounts = Accounts::new(p.clone()).await.unwrap(); assert_eq!(accounts.accounts.len(), 0); assert_eq!(accounts.config.get_selected_account().await, 0); @@ -543,7 +525,7 @@ mod tests { let dir = tempfile::tempdir()?; let p: PathBuf = dir.path().join("accounts").into(); - let mut accounts = Accounts::new("my_os".into(), p.clone()).await?; + let mut accounts = Accounts::new(p.clone()).await?; assert!(accounts.get_selected_account().await.is_none()); assert_eq!(accounts.config.get_selected_account().await, 0); @@ -564,14 +546,12 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let p: PathBuf = dir.path().join("accounts").into(); - let mut accounts = Accounts::new("my_os".into(), p.clone()).await.unwrap(); + let mut accounts = Accounts::new(p.clone()).await.unwrap(); assert_eq!(accounts.accounts.len(), 0); assert_eq!(accounts.config.get_selected_account().await, 0); let extern_dbfile: PathBuf = dir.path().join("other").into(); - let ctx = Context::new("my_os".into(), extern_dbfile.clone(), 0) - .await - .unwrap(); + let ctx = Context::new(extern_dbfile.clone(), 0).await.unwrap(); ctx.set_config(crate::config::Config::Addr, Some("me@mail.com")) .await .unwrap(); @@ -601,7 +581,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let p: PathBuf = dir.path().join("accounts").into(); - let mut accounts = Accounts::new("my_os".into(), p.clone()).await.unwrap(); + let mut accounts = Accounts::new(p.clone()).await.unwrap(); for expected_id in 1..10 { let id = accounts.add_account().await.unwrap(); @@ -621,7 +601,7 @@ mod tests { let dummy_accounts = 10; let (id0, id1, id2) = { - let mut accounts = Accounts::new("my_os".into(), p.clone()).await?; + let mut accounts = Accounts::new(p.clone()).await?; accounts.add_account().await?; let ids = accounts.get_all().await; assert_eq!(ids.len(), 1); @@ -656,7 +636,7 @@ mod tests { assert!(id2 > id1 + dummy_accounts); let (id0_reopened, id1_reopened, id2_reopened) = { - let accounts = Accounts::new("my_os".into(), p.clone()).await?; + let accounts = Accounts::new(p.clone()).await?; let ctx = accounts.get_selected_account().await.unwrap(); assert_eq!( ctx.get_config(crate::config::Config::Addr).await?, @@ -701,7 +681,7 @@ mod tests { let dir = tempfile::tempdir().unwrap(); let p: PathBuf = dir.path().join("accounts").into(); - let accounts = Accounts::new("my_os".into(), p.clone()).await?; + let accounts = Accounts::new(p.clone()).await?; // Make sure there are no accounts. assert_eq!(accounts.accounts.len(), 0); diff --git a/src/context.rs b/src/context.rs index ce3ddec38..c119035c1 100644 --- a/src/context.rs +++ b/src/context.rs @@ -47,7 +47,6 @@ pub struct InnerContext { /// Blob directory path pub(crate) blobdir: PathBuf, pub(crate) sql: Sql, - pub(crate) os_name: Option, pub(crate) bob: Bob, pub(crate) last_smeared_timestamp: RwLock, pub(crate) running_state: RwLock, @@ -108,7 +107,7 @@ pub fn get_info() -> BTreeMap<&'static str, String> { impl Context { /// Creates new context. - pub async fn new(os_name: String, dbfile: PathBuf, id: u32) -> Result { + pub async fn new(dbfile: PathBuf, id: u32) -> Result { // pretty_env_logger::try_init_timed().ok(); let mut blob_fname = OsString::new(); @@ -118,11 +117,10 @@ impl Context { if !blobdir.exists().await { async_std::fs::create_dir_all(&blobdir).await?; } - Context::with_blobdir(os_name, dbfile, blobdir, id).await + Context::with_blobdir(dbfile, blobdir, id).await } pub(crate) async fn with_blobdir( - os_name: String, dbfile: PathBuf, blobdir: PathBuf, id: u32, @@ -137,7 +135,6 @@ impl Context { id, blobdir, dbfile, - os_name: Some(os_name), running_state: RwLock::new(Default::default()), sql: Sql::new(), bob: Default::default(), @@ -653,7 +650,7 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let dbfile = tmp.path().join("db.sqlite"); std::fs::write(&dbfile, b"123").unwrap(); - let res = Context::new("FakeOs".into(), dbfile.into(), 1).await; + let res = Context::new(dbfile.into(), 1).await; assert!(res.is_err()); } @@ -804,9 +801,7 @@ mod tests { async fn test_blobdir_exists() { let tmp = tempfile::tempdir().unwrap(); let dbfile = tmp.path().join("db.sqlite"); - Context::new("FakeOS".into(), dbfile.into(), 1) - .await - .unwrap(); + Context::new(dbfile.into(), 1).await.unwrap(); let blobdir = tmp.path().join("db.sqlite-blobs"); assert!(blobdir.is_dir()); } @@ -817,7 +812,7 @@ mod tests { let dbfile = tmp.path().join("db.sqlite"); let blobdir = tmp.path().join("db.sqlite-blobs"); std::fs::write(&blobdir, b"123").unwrap(); - let res = Context::new("FakeOS".into(), dbfile.into(), 1).await; + let res = Context::new(dbfile.into(), 1).await; assert!(res.is_err()); } @@ -827,9 +822,7 @@ mod tests { let subdir = tmp.path().join("subdir"); let dbfile = subdir.join("db.sqlite"); let dbfile2 = dbfile.clone(); - Context::new("FakeOS".into(), dbfile.into(), 1) - .await - .unwrap(); + Context::new(dbfile.into(), 1).await.unwrap(); assert!(subdir.is_dir()); assert!(dbfile2.is_file()); } @@ -839,7 +832,7 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let dbfile = tmp.path().join("db.sqlite"); let blobdir = PathBuf::new(); - let res = Context::with_blobdir("FakeOS".into(), dbfile.into(), blobdir, 1).await; + let res = Context::with_blobdir(dbfile.into(), blobdir, 1).await; assert!(res.is_err()); } @@ -848,7 +841,7 @@ mod tests { let tmp = tempfile::tempdir().unwrap(); let dbfile = tmp.path().join("db.sqlite"); let blobdir = tmp.path().join("blobs"); - let res = Context::with_blobdir("FakeOS".into(), dbfile.into(), blobdir.into(), 1).await; + let res = Context::with_blobdir(dbfile.into(), blobdir.into(), 1).await; assert!(res.is_err()); } diff --git a/src/lib.rs b/src/lib.rs index 5a4102f0c..45f4a14ea 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -12,7 +12,8 @@ #![allow( clippy::match_bool, clippy::eval_order_dependence, - clippy::bool_assert_comparison + clippy::bool_assert_comparison, + clippy::manual_split_once )] #[macro_use] diff --git a/src/oauth2.rs b/src/oauth2.rs index f919a3faf..94060764e 100644 --- a/src/oauth2.rs +++ b/src/oauth2.rs @@ -41,6 +41,7 @@ struct Oauth2 { /// OAuth 2 Access Token Response #[derive(Debug, Deserialize)] +#[allow(dead_code)] struct Response { // Should always be there according to: // but previous code handled its abscense. diff --git a/src/pgp.rs b/src/pgp.rs index 5068ff7d6..820dff34a 100644 --- a/src/pgp.rs +++ b/src/pgp.rs @@ -248,7 +248,7 @@ pub async fn pk_encrypt( let pkeys: Vec = public_keys_for_encryption .keys() .iter() - .filter_map(|key| select_pk_for_encryption(key)) + .filter_map(select_pk_for_encryption) .collect(); let pkeys_refs: Vec<&SignedPublicKeyOrSubkey> = pkeys.iter().collect(); diff --git a/src/test_utils.rs b/src/test_utils.rs index 525e42587..ab0d494f0 100644 --- a/src/test_utils.rs +++ b/src/test_utils.rs @@ -99,7 +99,7 @@ impl TestContext { let mut context_names = CONTEXT_NAMES.write().unwrap(); context_names.insert(id, name); } - let ctx = Context::new("FakeOS".into(), dbfile.into(), id) + let ctx = Context::new(dbfile.into(), id) .await .expect("failed to create context");