Merge branch 'clippy-fix' into 'master'
Fix clippy lint See merge request famedly/conduit!121
This commit is contained in:
		
						commit
						f3e806096b
					
				
					 11 changed files with 81 additions and 98 deletions
				
			
		|  | @ -1 +1 @@ | ||||||
| 1.51.0 | 1.52.0 | ||||||
|  |  | ||||||
|  | @ -156,8 +156,7 @@ pub async fn register_route( | ||||||
|                 return Err(Error::Uiaa(uiaainfo)); |                 return Err(Error::Uiaa(uiaainfo)); | ||||||
|             } |             } | ||||||
|         // Success!
 |         // Success!
 | ||||||
|         } else { |         } else if let Some(json) = body.json_body { | ||||||
|             if let Some(json) = body.json_body { |  | ||||||
|             uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |             uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|             db.uiaa.create( |             db.uiaa.create( | ||||||
|                 &UserId::parse_with_server_name("", db.globals.server_name()) |                 &UserId::parse_with_server_name("", db.globals.server_name()) | ||||||
|  | @ -171,7 +170,6 @@ pub async fn register_route( | ||||||
|             return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |             return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     if missing_username { |     if missing_username { | ||||||
|         return Err(Error::BadRequest( |         return Err(Error::BadRequest( | ||||||
|  | @ -529,8 +527,7 @@ pub async fn change_password_route( | ||||||
|             return Err(Error::Uiaa(uiaainfo)); |             return Err(Error::Uiaa(uiaainfo)); | ||||||
|         } |         } | ||||||
|     // Success!
 |     // Success!
 | ||||||
|     } else { |     } else if let Some(json) = body.json_body { | ||||||
|         if let Some(json) = body.json_body { |  | ||||||
|         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|         db.uiaa |         db.uiaa | ||||||
|             .create(&sender_user, &sender_device, &uiaainfo, &json)?; |             .create(&sender_user, &sender_device, &uiaainfo, &json)?; | ||||||
|  | @ -538,7 +535,6 @@ pub async fn change_password_route( | ||||||
|     } else { |     } else { | ||||||
|         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     db.users |     db.users | ||||||
|         .set_password(&sender_user, Some(&body.new_password))?; |         .set_password(&sender_user, Some(&body.new_password))?; | ||||||
|  | @ -621,8 +617,7 @@ pub async fn deactivate_route( | ||||||
|             return Err(Error::Uiaa(uiaainfo)); |             return Err(Error::Uiaa(uiaainfo)); | ||||||
|         } |         } | ||||||
|     // Success!
 |     // Success!
 | ||||||
|     } else { |     } else if let Some(json) = body.json_body { | ||||||
|         if let Some(json) = body.json_body { |  | ||||||
|         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|         db.uiaa |         db.uiaa | ||||||
|             .create(&sender_user, &sender_device, &uiaainfo, &json)?; |             .create(&sender_user, &sender_device, &uiaainfo, &json)?; | ||||||
|  | @ -630,7 +625,6 @@ pub async fn deactivate_route( | ||||||
|     } else { |     } else { | ||||||
|         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     // Leave all joined rooms and reject all invitations
 |     // Leave all joined rooms and reject all invitations
 | ||||||
|     for room_id in db.rooms.rooms_joined(&sender_user).chain( |     for room_id in db.rooms.rooms_joined(&sender_user).chain( | ||||||
|  |  | ||||||
|  | @ -112,8 +112,7 @@ pub async fn delete_device_route( | ||||||
|             return Err(Error::Uiaa(uiaainfo)); |             return Err(Error::Uiaa(uiaainfo)); | ||||||
|         } |         } | ||||||
|     // Success!
 |     // Success!
 | ||||||
|     } else { |     } else if let Some(json) = body.json_body { | ||||||
|         if let Some(json) = body.json_body { |  | ||||||
|         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|         db.uiaa |         db.uiaa | ||||||
|             .create(&sender_user, &sender_device, &uiaainfo, &json)?; |             .create(&sender_user, &sender_device, &uiaainfo, &json)?; | ||||||
|  | @ -121,7 +120,6 @@ pub async fn delete_device_route( | ||||||
|     } else { |     } else { | ||||||
|         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     db.users.remove_device(&sender_user, &body.device_id)?; |     db.users.remove_device(&sender_user, &body.device_id)?; | ||||||
| 
 | 
 | ||||||
|  | @ -166,8 +164,7 @@ pub async fn delete_devices_route( | ||||||
|             return Err(Error::Uiaa(uiaainfo)); |             return Err(Error::Uiaa(uiaainfo)); | ||||||
|         } |         } | ||||||
|     // Success!
 |     // Success!
 | ||||||
|     } else { |     } else if let Some(json) = body.json_body { | ||||||
|         if let Some(json) = body.json_body { |  | ||||||
|         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|         db.uiaa |         db.uiaa | ||||||
|             .create(&sender_user, &sender_device, &uiaainfo, &json)?; |             .create(&sender_user, &sender_device, &uiaainfo, &json)?; | ||||||
|  | @ -175,7 +172,6 @@ pub async fn delete_devices_route( | ||||||
|     } else { |     } else { | ||||||
|         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     for device_id in &body.devices { |     for device_id in &body.devices { | ||||||
|         db.users.remove_device(&sender_user, &device_id)? |         db.users.remove_device(&sender_user, &device_id)? | ||||||
|  |  | ||||||
|  | @ -141,8 +141,7 @@ pub async fn upload_signing_keys_route( | ||||||
|             return Err(Error::Uiaa(uiaainfo)); |             return Err(Error::Uiaa(uiaainfo)); | ||||||
|         } |         } | ||||||
|     // Success!
 |     // Success!
 | ||||||
|     } else { |     } else if let Some(json) = body.json_body { | ||||||
|         if let Some(json) = body.json_body { |  | ||||||
|         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); |         uiaainfo.session = Some(utils::random_string(SESSION_ID_LENGTH)); | ||||||
|         db.uiaa |         db.uiaa | ||||||
|             .create(&sender_user, &sender_device, &uiaainfo, &json)?; |             .create(&sender_user, &sender_device, &uiaainfo, &json)?; | ||||||
|  | @ -150,7 +149,6 @@ pub async fn upload_signing_keys_route( | ||||||
|     } else { |     } else { | ||||||
|         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); |         return Err(Error::BadRequest(ErrorKind::NotJson, "Not json.")); | ||||||
|     } |     } | ||||||
|     } |  | ||||||
| 
 | 
 | ||||||
|     if let Some(master_key) = &body.master_key { |     if let Some(master_key) = &body.master_key { | ||||||
|         db.users.add_cross_signing_keys( |         db.users.add_cross_signing_keys( | ||||||
|  |  | ||||||
|  | @ -25,20 +25,22 @@ pub async fn search_users_route( | ||||||
|             avatar_url: db.users.avatar_url(&user_id).ok()?, |             avatar_url: db.users.avatar_url(&user_id).ok()?, | ||||||
|         }; |         }; | ||||||
| 
 | 
 | ||||||
|         if !user |         let user_id_matches = user | ||||||
|             .user_id |             .user_id | ||||||
|             .to_string() |             .to_string() | ||||||
|             .to_lowercase() |             .to_lowercase() | ||||||
|             .contains(&body.search_term.to_lowercase()) |             .contains(&body.search_term.to_lowercase()); | ||||||
|             && user | 
 | ||||||
|  |         let user_displayname_matches = user | ||||||
|             .display_name |             .display_name | ||||||
|             .as_ref() |             .as_ref() | ||||||
|             .filter(|name| { |             .filter(|name| { | ||||||
|                 name.to_lowercase() |                 name.to_lowercase() | ||||||
|                     .contains(&body.search_term.to_lowercase()) |                     .contains(&body.search_term.to_lowercase()) | ||||||
|             }) |             }) | ||||||
|                 .is_none() |             .is_some(); | ||||||
|         { | 
 | ||||||
|  |         if !user_id_matches && !user_displayname_matches { | ||||||
|             return None; |             return None; | ||||||
|         } |         } | ||||||
| 
 | 
 | ||||||
|  |  | ||||||
|  | @ -368,7 +368,7 @@ impl Database { | ||||||
|             if db.globals.database_version()? < 3 { |             if db.globals.database_version()? < 3 { | ||||||
|                 // Move media to filesystem
 |                 // Move media to filesystem
 | ||||||
|                 for (key, content) in db.media.mediaid_file.iter() { |                 for (key, content) in db.media.mediaid_file.iter() { | ||||||
|                     if content.len() == 0 { |                     if content.is_empty() { | ||||||
|                         continue; |                         continue; | ||||||
|                     } |                     } | ||||||
| 
 | 
 | ||||||
|  | @ -614,8 +614,8 @@ impl<'r> FromRequest<'r> for DatabaseGuard { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| impl Into<DatabaseGuard> for OwnedRwLockReadGuard<Database> { | impl From<OwnedRwLockReadGuard<Database>> for DatabaseGuard { | ||||||
|     fn into(self) -> DatabaseGuard { |     fn from(val: OwnedRwLockReadGuard<Database>) -> Self { | ||||||
|         DatabaseGuard(self) |         Self(val) | ||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -121,7 +121,7 @@ impl Pool { | ||||||
| 
 | 
 | ||||||
|         let spilled = Self::prepare_conn(&self.path, None).unwrap(); |         let spilled = Self::prepare_conn(&self.path, None).unwrap(); | ||||||
| 
 | 
 | ||||||
|         return HoldingConn::FromOwned(spilled, spill_arc); |         HoldingConn::FromOwned(spilled, spill_arc) | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -250,16 +250,7 @@ macro_rules! iter_from_thread { | ||||||
| 
 | 
 | ||||||
| impl Tree for SqliteTable { | impl Tree for SqliteTable { | ||||||
|     fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> { |     fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>> { | ||||||
|         let guard = self.engine.pool.read_lock(); |         self.get_with_guard(&self.engine.pool.read_lock(), key) | ||||||
| 
 |  | ||||||
|         // let start = Instant::now();
 |  | ||||||
| 
 |  | ||||||
|         let val = self.get_with_guard(&guard, key); |  | ||||||
| 
 |  | ||||||
|         // debug!("get:       took {:?}", start.elapsed());
 |  | ||||||
|         // debug!("get key: {:?}", &key)
 |  | ||||||
| 
 |  | ||||||
|         val |  | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> { |     fn insert(&self, key: &[u8], value: &[u8]) -> Result<()> { | ||||||
|  |  | ||||||
|  | @ -16,7 +16,7 @@ use std::{ | ||||||
|     sync::{Arc, RwLock}, |     sync::{Arc, RwLock}, | ||||||
|     time::{Duration, Instant}, |     time::{Duration, Instant}, | ||||||
| }; | }; | ||||||
| use tokio::sync::{broadcast, Semaphore}; | use tokio::sync::{broadcast, watch::Receiver, Semaphore}; | ||||||
| use trust_dns_resolver::TokioAsyncResolver; | use trust_dns_resolver::TokioAsyncResolver; | ||||||
| 
 | 
 | ||||||
| use super::abstraction::Tree; | use super::abstraction::Tree; | ||||||
|  | @ -26,6 +26,11 @@ pub const COUNTER: &[u8] = b"c"; | ||||||
| type WellKnownMap = HashMap<Box<ServerName>, (String, String)>; | type WellKnownMap = HashMap<Box<ServerName>, (String, String)>; | ||||||
| type TlsNameMap = HashMap<String, webpki::DNSName>; | type TlsNameMap = HashMap<String, webpki::DNSName>; | ||||||
| type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
 | type RateLimitState = (Instant, u32); // Time if last failed try, number of failed tries
 | ||||||
|  | type SyncHandle = ( | ||||||
|  |     Option<String>,                                         // since
 | ||||||
|  |     Receiver<Option<ConduitResult<sync_events::Response>>>, // rx
 | ||||||
|  | ); | ||||||
|  | 
 | ||||||
| pub struct Globals { | pub struct Globals { | ||||||
|     pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
 |     pub actual_destination_cache: Arc<RwLock<WellKnownMap>>, // actual_destination, host
 | ||||||
|     pub tls_name_override: Arc<RwLock<TlsNameMap>>, |     pub tls_name_override: Arc<RwLock<TlsNameMap>>, | ||||||
|  | @ -39,15 +44,7 @@ pub struct Globals { | ||||||
|     pub bad_event_ratelimiter: Arc<RwLock<BTreeMap<EventId, RateLimitState>>>, |     pub bad_event_ratelimiter: Arc<RwLock<BTreeMap<EventId, RateLimitState>>>, | ||||||
|     pub bad_signature_ratelimiter: Arc<RwLock<BTreeMap<Vec<String>, RateLimitState>>>, |     pub bad_signature_ratelimiter: Arc<RwLock<BTreeMap<Vec<String>, RateLimitState>>>, | ||||||
|     pub servername_ratelimiter: Arc<RwLock<BTreeMap<Box<ServerName>, Arc<Semaphore>>>>, |     pub servername_ratelimiter: Arc<RwLock<BTreeMap<Box<ServerName>, Arc<Semaphore>>>>, | ||||||
|     pub sync_receivers: RwLock< |     pub sync_receivers: RwLock<BTreeMap<(UserId, Box<DeviceId>), SyncHandle>>, | ||||||
|         BTreeMap< |  | ||||||
|             (UserId, Box<DeviceId>), |  | ||||||
|             ( |  | ||||||
|                 Option<String>, |  | ||||||
|                 tokio::sync::watch::Receiver<Option<ConduitResult<sync_events::Response>>>, |  | ||||||
|             ), // since, rx
 |  | ||||||
|         >, |  | ||||||
|     >, |  | ||||||
|     pub rotate: RotationHandler, |     pub rotate: RotationHandler, | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -109,6 +106,12 @@ impl RotationHandler { | ||||||
|     } |     } | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | impl Default for RotationHandler { | ||||||
|  |     fn default() -> Self { | ||||||
|  |         Self::new() | ||||||
|  |     } | ||||||
|  | } | ||||||
|  | 
 | ||||||
| impl Globals { | impl Globals { | ||||||
|     pub fn load( |     pub fn load( | ||||||
|         globals: Arc<dyn Tree>, |         globals: Arc<dyn Tree>, | ||||||
|  |  | ||||||
|  | @ -54,6 +54,7 @@ impl Media { | ||||||
|     } |     } | ||||||
| 
 | 
 | ||||||
|     /// Uploads or replaces a file thumbnail.
 |     /// Uploads or replaces a file thumbnail.
 | ||||||
|  |     #[allow(clippy::too_many_arguments)] | ||||||
|     pub async fn upload_thumbnail( |     pub async fn upload_thumbnail( | ||||||
|         &self, |         &self, | ||||||
|         mxc: String, |         mxc: String, | ||||||
|  |  | ||||||
|  | @ -533,17 +533,15 @@ impl Rooms { | ||||||
|                     r |                     r | ||||||
|                 }, |                 }, | ||||||
|                 |pduid| { |                 |pduid| { | ||||||
|                     let r = Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { |                     Ok(Some(self.pduid_pdu.get(&pduid)?.ok_or_else(|| { | ||||||
|                         Error::bad_database("Invalid pduid in eventid_pduid.") |                         Error::bad_database("Invalid pduid in eventid_pduid.") | ||||||
|                     })?)); |                     })?)) | ||||||
|                     r |  | ||||||
|                 }, |                 }, | ||||||
|             )? |             )? | ||||||
|             .map(|pdu| { |             .map(|pdu| { | ||||||
|                 let r = serde_json::from_slice(&pdu) |                 serde_json::from_slice(&pdu) | ||||||
|                     .map_err(|_| Error::bad_database("Invalid PDU in db.")) |                     .map_err(|_| Error::bad_database("Invalid PDU in db.")) | ||||||
|                     .map(Arc::new); |                     .map(Arc::new) | ||||||
|                 r |  | ||||||
|             }) |             }) | ||||||
|             .transpose()? |             .transpose()? | ||||||
|         { |         { | ||||||
|  | @ -1112,7 +1110,7 @@ impl Rooms { | ||||||
|                 } |                 } | ||||||
|             }; |             }; | ||||||
| 
 | 
 | ||||||
|             new_state.insert(shortstatekey, shorteventid.into()); |             new_state.insert(shortstatekey, shorteventid); | ||||||
| 
 | 
 | ||||||
|             let new_state_hash = self.calculate_hash( |             let new_state_hash = self.calculate_hash( | ||||||
|                 &new_state |                 &new_state | ||||||
|  |  | ||||||
|  | @ -137,7 +137,7 @@ pub fn deserialize_from_str< | ||||||
|         where |         where | ||||||
|             E: serde::de::Error, |             E: serde::de::Error, | ||||||
|         { |         { | ||||||
|             v.parse().map_err(|e| serde::de::Error::custom(e)) |             v.parse().map_err(serde::de::Error::custom) | ||||||
|         } |         } | ||||||
|     } |     } | ||||||
|     deserializer.deserialize_str(Visitor(std::marker::PhantomData)) |     deserializer.deserialize_str(Visitor(std::marker::PhantomData)) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in a new issue