diff --git a/client/src/client_connection.rs b/client/src/client_connection.rs index fd128b6..d1d9e33 100644 --- a/client/src/client_connection.rs +++ b/client/src/client_connection.rs @@ -20,6 +20,8 @@ use uuid::Uuid; // Waiting Task System // ============================================================================ +type WaitingTask = Box, CommunicationValue) -> bool + Send + Sync>; + #[allow(dead_code)] pub struct ClientConnection { sender: Arc>>>, @@ -27,8 +29,7 @@ pub struct ClientConnection { connection_loop_handle: Arc>>>, pub connection_id: Uuid, shutdown_tx: Arc>>>, - pub waiting_tasks: - DashMap, CommunicationValue) -> bool + Send + Sync>>, + pub waiting_tasks: DashMap, shutdown: Arc>, keyring: Arc>>>, } @@ -40,10 +41,7 @@ impl ClientConnection { connection_loop_handle: Arc>>>, connection_id: Uuid, shutdown_tx: Arc>>>, - waiting_tasks: DashMap< - u32, - Box, CommunicationValue) -> bool + Send + Sync>, - >, + waiting_tasks: DashMap, shutdown: Arc>, ) -> Self { Self { @@ -357,7 +355,6 @@ impl ClientConnection { .add_typed_default(DataType::Settings, DataValue::Array(settings_json)); self.send_message(&response).await; - return; } } @@ -374,7 +371,7 @@ impl ClientConnection { if let Some(solved) = solved { let response = CommunicationValue::new(CommunicationType::ChallengeResponse) - .with_request_id(&cv) + .with_request_id(cv) .add_typed_default(DataType::Challenge, DataValue::Str(solved)); self.send_message(&response).await; diff --git a/iota-cli/src/elements/console_card.rs b/iota-cli/src/elements/console_card.rs index db7a40b..8f416a5 100644 --- a/iota-cli/src/elements/console_card.rs +++ b/iota-cli/src/elements/console_card.rs @@ -488,12 +488,11 @@ impl InteractableElement for ConsoleCard { if !key .modifiers .intersects(KeyModifiers::CONTROL | KeyModifiers::ALT) + && let Some(c) = key.code.as_char() { - if let Some(c) = key.code.as_char() { - self.insert_at_cursor(c); - self.message = None; - return IotaInteraction::Changed; - } + self.insert_at_cursor(c); + self.message = None; + return IotaInteraction::Changed; } IotaInteraction::Unhandled } diff --git a/iota-cli/src/elements/log_card.rs b/iota-cli/src/elements/log_card.rs index 7c7200d..4dac573 100755 --- a/iota-cli/src/elements/log_card.rs +++ b/iota-cli/src/elements/log_card.rs @@ -435,7 +435,7 @@ impl JoinableElement for LogCard { } fn as_element(&self) -> &(dyn Element + 'static) { - &*self + self } fn as_element_mut(&mut self) -> &mut (dyn Element + 'static) { @@ -461,7 +461,7 @@ impl InteractableElement for LogCard { } fn as_element(&self) -> &(dyn Element + 'static) { - &*self + self } fn as_element_mut(&mut self) -> &mut (dyn Element + 'static) { diff --git a/iota-cli/src/help_overlay.rs b/iota-cli/src/help_overlay.rs index f9375a3..64bdfee 100644 --- a/iota-cli/src/help_overlay.rs +++ b/iota-cli/src/help_overlay.rs @@ -137,6 +137,12 @@ impl HelpOverlay { } } +impl Default for HelpOverlay { + fn default() -> Self { + Self::new() + } +} + impl IotaScreen for HelpOverlay { fn render_legacy(&self, f: &mut Frame, rect: Rect, theme: &ResolvedTheme, _hits: &mut HitMap) { let area = ratatool::layout::centered_rect( diff --git a/iota-cli/src/lib.rs b/iota-cli/src/lib.rs index 83e3584..bc3e81e 100644 --- a/iota-cli/src/lib.rs +++ b/iota-cli/src/lib.rs @@ -1,3 +1,8 @@ +#![allow( + clippy::module_inception, + reason = "preserve existing public module paths" +)] + pub mod elements { pub mod console_card; pub mod elements; diff --git a/iota-cli/src/screens/md_viewer.rs b/iota-cli/src/screens/md_viewer.rs index 8eae8cc..5a36ff8 100644 --- a/iota-cli/src/screens/md_viewer.rs +++ b/iota-cli/src/screens/md_viewer.rs @@ -334,7 +334,7 @@ fn table_to_lines(table: Vec>, theme: &ResolvedTheme) -> Vec match self.focus { Focus::Eula => { @@ -678,9 +678,7 @@ impl IotaScreen for TermsUpdaterScreen { }; if let Some(terms_type) = terms_type { - return IotaInteraction::Effect(IotaEffect::LoadNewestTerms { - kind: terms_type, - }); + IotaInteraction::Effect(IotaEffect::LoadNewestTerms { kind: terms_type }) } else { IotaInteraction::Unhandled } diff --git a/iota-cli/src/screens/users/mod.rs b/iota-cli/src/screens/users/mod.rs index da14ca6..c08f3b0 100644 --- a/iota-cli/src/screens/users/mod.rs +++ b/iota-cli/src/screens/users/mod.rs @@ -698,7 +698,7 @@ impl IotaScreen for UsersScreen { } Err(error) => self.message = Some(error), } - return IotaInteraction::Changed; + IotaInteraction::Changed } UiEvent::Message(IotaMessage::Event(AppEvent::UserOperationFinished(result))) => { self.pending = false; @@ -706,7 +706,7 @@ impl IotaScreen for UsersScreen { Ok(message) => message, Err(error) => error, }); - return self.refresh(); + self.refresh() } UiEvent::Message(IotaMessage::Event(AppEvent::CredentialExportFinished(result))) => { self.pending = false; @@ -714,7 +714,7 @@ impl IotaScreen for UsersScreen { Ok(message) => message, Err(error) => error, }); - return IotaInteraction::Changed; + IotaInteraction::Changed } UiEvent::Message(IotaMessage::Event(AppEvent::TuInspected(result))) => { if let Some(UsersOverlay::Add(flow)) = self.overlay.as_mut() { @@ -727,7 +727,7 @@ impl IotaScreen for UsersScreen { } } } - return IotaInteraction::Changed; + IotaInteraction::Changed } UiEvent::Paste(text) => { if let Some(UsersOverlay::Add(flow)) = self.overlay.as_mut() { @@ -753,7 +753,7 @@ impl IotaScreen for UsersScreen { self.restore_selection(); return IotaInteraction::Changed; } - return IotaInteraction::Unhandled; + IotaInteraction::Unhandled } UiEvent::Key(key) => { if let Some(overlay) = &mut self.overlay { diff --git a/iota-cli/src/theme/config.rs b/iota-cli/src/theme/config.rs index 26d6046..81c882e 100644 --- a/iota-cli/src/theme/config.rs +++ b/iota-cli/src/theme/config.rs @@ -129,7 +129,7 @@ impl UiConfig { } pub fn load() -> Result { - let path = match (|| std::panic::catch_unwind(|| Self::path()))() { + let path = match std::panic::catch_unwind(Self::path) { Ok(path) => path, Err(_) => Self::fallback_path().ok_or_else(|| { io::Error::new(io::ErrorKind::NotFound, "could not determine config path") diff --git a/iota-cli/src/theme/mod.rs b/iota-cli/src/theme/mod.rs index be14a82..c05a3d1 100644 --- a/iota-cli/src/theme/mod.rs +++ b/iota-cli/src/theme/mod.rs @@ -129,13 +129,11 @@ pub fn resolve_with_capabilities( }; theme.name = name; theme.unicode = unicode_enabled; - if !unicode_enabled { - if matches!(theme.console.cursor, CursorPresentation::Character { .. }) { - theme.console.cursor = CursorPresentation::Character { - glyph: "|", - style: theme.console.text, - }; - } + if !unicode_enabled && matches!(theme.console.cursor, CursorPresentation::Character { .. }) { + theme.console.cursor = CursorPresentation::Character { + glyph: "|", + style: theme.console.text, + }; } theme } diff --git a/iota-cli/src/theme/presets.rs b/iota-cli/src/theme/presets.rs index 301339a..698c1fb 100644 --- a/iota-cli/src/theme/presets.rs +++ b/iota-cli/src/theme/presets.rs @@ -27,6 +27,7 @@ fn choice( suffix, } } +#[expect(clippy::too_many_arguments, reason = "explicit theme styles")] fn base( name: ThemeName, normal: Style, diff --git a/iota-cli/src/util/buttons.rs b/iota-cli/src/util/buttons.rs index a69d2ad..21cedae 100644 --- a/iota-cli/src/util/buttons.rs +++ b/iota-cli/src/util/buttons.rs @@ -8,6 +8,10 @@ use crate::{ util::terms_focus::Focus, }; +#[expect( + clippy::too_many_arguments, + reason = "explicit button layout and styling" +)] pub fn draw_buttons( frame: &mut ratatui::Frame, area: Rect, diff --git a/iota-connection/src/message_handlers.rs b/iota-connection/src/message_handlers.rs index 410f6b1..cf166ea 100644 --- a/iota-connection/src/message_handlers.rs +++ b/iota-connection/src/message_handlers.rs @@ -1,3 +1,8 @@ +#![allow( + clippy::result_large_err, + reason = "return protocol error frames directly to the sender" +)] + use crate::message_common::*; use iota_logger::{LogLevel, PrintType, log_event}; use iota_storage::util::call_envelopes::{self, CallEnvelope}; @@ -1582,10 +1587,8 @@ pub fn handle_global_settings_save(cv: &CommunicationValue) -> CommunicationValu .with_request_id(cv); if let Some(session_id) = cv.get_data(DataType::SessionId).as_number() { - response = response.add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + response = + response.add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } response @@ -1612,10 +1615,8 @@ pub fn handle_global_settings_load(cv: &CommunicationValue) -> CommunicationValu ); if let Some(session_id) = cv.get_data(DataType::SessionId).as_number() { - response = response.add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + response = response + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } return response; @@ -1627,10 +1628,8 @@ pub fn handle_global_settings_load(cv: &CommunicationValue) -> CommunicationValu .add_typed_default(DataType::Payload, DataValue::Str(settings_value_str)); if let Some(session_id) = cv.get_data(DataType::SessionId).as_number() { - response = response.add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + response = + response.add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } response @@ -1664,10 +1663,7 @@ pub fn handle_settings_save( DataType::Message, DataValue::Str("Invalid session_id".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); }; let Some(settings_name) = cv.get_data(DataType::SettingsName).as_str() else { return CommunicationValue::new(CommunicationType::ErrorInvalidData) @@ -1677,10 +1673,7 @@ pub fn handle_settings_save( DataType::Message, DataValue::Str("Missing settings_name".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); }; let Some(settings_value) = cv.get_data(DataType::Payload).as_str() else { return CommunicationValue::new(CommunicationType::ErrorInvalidData) @@ -1690,10 +1683,7 @@ pub fn handle_settings_save( DataType::Message, DataValue::Str("Missing settings payload".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); }; if !settings_name @@ -1712,10 +1702,7 @@ pub fn handle_settings_save( DataType::SettingsName, DataValue::Str(settings_name.to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } let Ok(session_id_i64) = i64::try_from(session_id) else { return error_response(cv, CommunicationType::ErrorInvalidData); @@ -1732,10 +1719,7 @@ pub fn handle_settings_save( DataType::SettingsName, DataValue::Str(settings_name.to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ) + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)) } pub fn handle_settings_load( @@ -1766,10 +1750,7 @@ pub fn handle_settings_load( DataType::Message, DataValue::Str("Invalid session_id".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } let Ok(session_id_i64) = i64::try_from(session_id) else { return error_response(cv, CommunicationType::ErrorInvalidData); @@ -1782,10 +1763,7 @@ pub fn handle_settings_load( DataType::Message, DataValue::Str("Missing settings_name".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); }; if !settings_name @@ -1804,10 +1782,7 @@ pub fn handle_settings_load( DataType::SettingsName, DataValue::Str(settings_name.to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } let Ok(settings_value) = settings::load(my_id_i64, session_id_i64, settings_name) else { @@ -1821,10 +1796,7 @@ pub fn handle_settings_load( DataType::SettingsName, DataValue::Str(settings_name.to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); }; CommunicationValue::new(CommunicationType::SettingsLoad) @@ -1835,10 +1807,7 @@ pub fn handle_settings_load( DataType::SettingsName, DataValue::Str(settings_name.to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ) + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)) } pub fn handle_settings_list( @@ -1869,10 +1838,7 @@ pub fn handle_settings_list( DataType::Message, DataValue::Str("Invalid session_id".to_string()), ) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ); + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)); } let Ok(session_id_i64) = i64::try_from(session_id) else { return error_response(cv, CommunicationType::ErrorInvalidData); @@ -1886,10 +1852,7 @@ pub fn handle_settings_list( .with_request_id(cv) .with_receiver(my_id) .add_typed_default(DataType::Settings, DataValue::Array(settings_json)) - .add_typed_default( - DataType::SessionId, - DataValue::SignedNumber(session_id as i128), - ) + .add_typed_default(DataType::SessionId, DataValue::SignedNumber(session_id)) } fn setting_response( diff --git a/iota-core/src/consent_state.rs b/iota-core/src/consent_state.rs index 35a4b37..0374ea5 100644 --- a/iota-core/src/consent_state.rs +++ b/iota-core/src/consent_state.rs @@ -186,7 +186,7 @@ async fn get_updates() -> Option<( { let file = load_file("", "agreements"); let accepted_state = ConsentState::from_str(&file).sanitize(); - save_file("", "agreements", &accepted_state.to_string()); + save_file("", "agreements", &accepted_state.serialize()); let eula_update: UpdateDecision = if current_eula.equals_some(&accepted_state.eula) { if current_eula.equals(&newest_eula) { @@ -293,23 +293,23 @@ impl ConsentState { .unwrap() .as_secs(); - if let Some(future_eula) = self.future_eula.clone() { - if future_eula.get_time() < current_secs { - self.eula = Some(future_eula); - self.future_eula = None; - } + if let Some(future_eula) = self.future_eula.clone() + && future_eula.get_time() < current_secs + { + self.eula = Some(future_eula); + self.future_eula = None; } - if let Some(future_tos) = self.future_tos.clone() { - if future_tos.get_time() < current_secs { - self.tos = Some(future_tos); - self.future_tos = None; - } + if let Some(future_tos) = self.future_tos.clone() + && future_tos.get_time() < current_secs + { + self.tos = Some(future_tos); + self.future_tos = None; } - if let Some(future_privacy) = self.future_privacy.clone() { - if future_privacy.get_time() < current_secs { - self.privacy = Some(future_privacy); - self.future_privacy = None; - } + if let Some(future_privacy) = self.future_privacy.clone() + && future_privacy.get_time() < current_secs + { + self.privacy = Some(future_privacy); + self.future_privacy = None; } if !self.accepted_eula { @@ -325,10 +325,10 @@ impl ConsentState { } pub fn save_state(&self) { - save_file("", "agreements", &self.to_string()); + save_file("", "agreements", &self.serialize()); } - fn to_string(&self) -> String { + fn serialize(&self) -> String { let current_secs = SystemTime::now() .duration_since(UNIX_EPOCH) .unwrap() @@ -487,7 +487,8 @@ impl ConsentState { let future_eula_time = future_eula_time.parse::().unwrap_or(0); let future_tos_time = future_tos_time.parse::().unwrap_or(0); let future_pp_time = future_pp_time.parse::().unwrap_or(0); - let state = Self { + + Self { accepted_eula: eula, eula: Some(Doc::new(eula_version, eula_hash, Type::EULA, unix)), accepted_pp: pp, @@ -525,9 +526,7 @@ impl ConsentState { None }, } - .sanitize(); - - state + .sanitize() } } diff --git a/iota-daemon-lib/src/ipc_server.rs b/iota-daemon-lib/src/ipc_server.rs index b90e71f..656c786 100644 --- a/iota-daemon-lib/src/ipc_server.rs +++ b/iota-daemon-lib/src/ipc_server.rs @@ -37,6 +37,7 @@ struct ClientSubscription { metric_interval_ms: u64, } +#[expect(clippy::large_enum_variant, reason = "keep queued IPC messages inline")] enum WriterCommand { Message(DaemonMessage), Flush { @@ -94,6 +95,7 @@ impl IpcServer { .join("daemon.lock"); let lock = File::options() .create(true) + .truncate(false) .mode(0o600) .read(true) .write(true) @@ -478,15 +480,13 @@ async fn handle_client( Ok(DaemonMessage::LogEntry(entry)) => { // Filter by subscribed log classes let log_classes = sub_rx.borrow().log_classes.clone(); - if log_classes.is_empty() - || log_classes.iter().any(|c| entry.sender == *c) - { - if let Err(error) = write_client_message(&mut writer, &DaemonMessage::LogEntry(entry)).await { + if (log_classes.is_empty() + || log_classes.contains(&entry.sender)) + && let Err(error) = write_client_message(&mut writer, &DaemonMessage::LogEntry(entry)).await { eprintln!("IPC client writer stopped while sending log message: {error}"); session_cancellation.cancel(); break; } - } } Ok(DaemonMessage::MetricSample(sample)) => { // Rate-limit metric samples based on subscription interval diff --git a/iota-daemon-lib/src/task_registry.rs b/iota-daemon-lib/src/task_registry.rs index 89769db..e192486 100644 --- a/iota-daemon-lib/src/task_registry.rs +++ b/iota-daemon-lib/src/task_registry.rs @@ -3,9 +3,11 @@ use std::time::Duration; use tokio::sync::Mutex; use tokio::task::JoinSet; +type TaskOutcome = (String, Result<(), String>); + #[derive(Clone, Default)] pub struct TaskRegistry { - tasks: Arc)>>>, + tasks: Arc>>, } impl TaskRegistry { diff --git a/iota-ipc/src/protocol.rs b/iota-ipc/src/protocol.rs index 9ca95e3..65726ef 100644 --- a/iota-ipc/src/protocol.rs +++ b/iota-ipc/src/protocol.rs @@ -322,6 +322,10 @@ pub struct ResponseEnvelope { #[derive(Clone, Debug, Deserialize, Serialize)] #[serde(tag = "type", content = "data", rename_all = "snake_case")] +#[expect( + clippy::large_enum_variant, + reason = "keep IPC response payloads inline" +)] pub enum ResponseResult { Ok(ResponsePayload), Error(IpcErrorCode), @@ -724,9 +728,10 @@ pub enum ConnectionStatus { Disconnected, } -#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize)] +#[derive(Clone, Copy, Debug, Default, PartialEq, Eq, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] pub enum StartupPhase { + #[default] Starting, MigratingStorage, LoadingUsers, @@ -793,12 +798,6 @@ pub struct ComponentHealth { pub changed_at_ms: u128, } -impl Default for StartupPhase { - fn default() -> Self { - Self::Starting - } -} - // --------------------------------------------------------------------------- // Shared types // --------------------------------------------------------------------------- diff --git a/iota-logger/src/lib.rs b/iota-logger/src/lib.rs index 58f20ad..5656bff 100644 --- a/iota-logger/src/lib.rs +++ b/iota-logger/src/lib.rs @@ -189,10 +189,10 @@ pub fn startup_with_log_dir_and_capacity(log_dir: Option, queue_capacit format!("{prefix}{resolved_message}") ); - if let Some(file) = file.as_mut() { - if let Err(error) = writeln!(file, "{line}") { - eprintln!("Unable to write Iota log file: {error}"); - } + if let Some(file) = file.as_mut() + && let Err(error) = writeln!(file, "{line}") + { + eprintln!("Unable to write Iota log file: {error}"); } let _ = writeln!(std::io::stderr(), "{timestamp} {line}"); @@ -313,10 +313,10 @@ fn report_dropped_logs( let line = format!( "{timestamp_ms} level=ERROR component=general direction=internal sender=- event=logger.dropped message={message:?}" ); - if let Some(file) = file { - if let Err(error) = writeln!(file, "{line}") { - eprintln!("Unable to write Iota log file: {error}"); - } + if let Some(file) = file + && let Err(error) = writeln!(file, "{line}") + { + eprintln!("Unable to write Iota log file: {error}"); } eprintln!("{line}"); let _ = broadcaster.send(UiLogEntry { @@ -632,6 +632,36 @@ fn format_data_container(data: &[(DataTypeId, DataValue)], type_map: &TypeMap) - .join(", ") } +#[macro_export] +macro_rules! log_cv { + ($kind:expr, $cv:expr) => { + $crate::log_cv_internal("", &$cv, Some($kind)) + }; + ($cv:expr) => { + $crate::log_cv_internal("", &$cv, None) + }; +} + +#[macro_export] +macro_rules! log_cv_in { + ($kind:expr, $cv:expr) => { + $crate::log_cv_internal("> ", &$cv, Some($kind)) + }; + ($cv:expr) => { + $crate::log_cv_internal("> ", $cv, None) + }; +} + +#[macro_export] +macro_rules! log_cv_out { + ($kind:expr, $cv:expr) => { + $crate::log_cv_internal("< ", &$cv, Some($kind)) + }; + ($cv:expr) => { + $crate::log_cv_internal("< ", $cv, None) + }; +} + #[cfg(test)] mod tests { use super::format_cv; @@ -662,33 +692,3 @@ mod tests { ); } } - -#[macro_export] -macro_rules! log_cv { - ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("", &$cv, Some($kind)) - }; - ($cv:expr) => { - $crate::log_cv_internal("", &$cv, None) - }; -} - -#[macro_export] -macro_rules! log_cv_in { - ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("> ", &$cv, Some($kind)) - }; - ($cv:expr) => { - $crate::log_cv_internal("> ", $cv, None) - }; -} - -#[macro_export] -macro_rules! log_cv_out { - ($kind:expr, $cv:expr) => { - $crate::log_cv_internal("< ", &$cv, Some($kind)) - }; - ($cv:expr) => { - $crate::log_cv_internal("< ", $cv, None) - }; -} diff --git a/iota-process-manager/src/lib.rs b/iota-process-manager/src/lib.rs index 3512a90..323f6d3 100644 --- a/iota-process-manager/src/lib.rs +++ b/iota-process-manager/src/lib.rs @@ -319,7 +319,7 @@ mod systemd { } let executor: Arc = Arc::new(RealExecutor); let mut manager = executor - .output("systemctl", &["--version", &COMMON[0], &COMMON[1]]) + .output("systemctl", &["--version", COMMON[0], COMMON[1]]) .await .ok() .filter(|r| r.success) @@ -573,10 +573,10 @@ mod systemd { let deadline = tokio::time::Instant::now() + Duration::from_secs(2); let pid = loop { - if let Ok(contents) = fs::read_to_string(&pid_file) { - if let Ok(pid) = contents.parse::() { - break pid; - } + if let Ok(contents) = fs::read_to_string(&pid_file) + && let Ok(pid) = contents.parse::() + { + break pid; } assert!(tokio::time::Instant::now() < deadline); tokio::task::yield_now().await; diff --git a/iota-state/src/lib.rs b/iota-state/src/lib.rs index 8f668ea..14b6ea3 100644 --- a/iota-state/src/lib.rs +++ b/iota-state/src/lib.rs @@ -215,6 +215,12 @@ impl AppState { } } +impl Default for AppState { + fn default() -> Self { + Self::new() + } +} + #[cfg(feature = "legacy-globals")] #[deprecated(note = "use DaemonState or ClientState")] pub static APP_STATE: LazyLock>> = @@ -228,7 +234,7 @@ pub static SHUTDOWN: Lazy> = Lazy::new(|| RwLock::new(false)); pub static RELOAD: Lazy> = Lazy::new(|| RwLock::new(true)); #[cfg(feature = "legacy-globals")] #[deprecated(note = "use DaemonState")] -pub static ACTIVE_TASKS: Lazy> = Lazy::new(|| DashSet::new()); +pub static ACTIVE_TASKS: Lazy> = Lazy::new(DashSet::new); #[cfg(feature = "legacy-globals")] pub fn setup(state: &DaemonState) { diff --git a/iota-storage/src/users/contact.rs b/iota-storage/src/users/contact.rs index a175d04..107a2db 100644 --- a/iota-storage/src/users/contact.rs +++ b/iota-storage/src/users/contact.rs @@ -1,4 +1,4 @@ -#[derive(Debug, Clone)] +#[derive(Debug, Clone, Default)] pub struct Contact { pub user_id: i64, pub principal: Option, @@ -9,20 +9,6 @@ pub struct Contact { pub notifications_read_at: i64, } -impl Default for Contact { - fn default() -> Self { - Contact { - user_id: 0, - principal: None, - user_name: None, - created_at: 0, - last_message_at: None, - notifications: 0, - notifications_read_at: 0, - } - } -} - impl Contact { pub fn new(user_id: i64) -> Self { let created_at = std::time::SystemTime::now() diff --git a/iota-storage/src/users/user_manager.rs b/iota-storage/src/users/user_manager.rs index 1f57421..2c17cc2 100644 --- a/iota-storage/src/users/user_manager.rs +++ b/iota-storage/src/users/user_manager.rs @@ -682,12 +682,12 @@ pub fn load_users_sync() -> std::io::Result<()> { if content.trim().is_empty() { return Ok(()); } - if let Ok(parsed) = json::parse(&content) { - if let json::JsonValue::Array(arr) = parsed { - for j in arr.iter() { - if let Some(up) = UserProfile::from_json(j) { - try_add_user(up).map_err(|error| std::io::Error::other(error.to_string()))?; - } + if let Ok(parsed) = json::parse(&content) + && let json::JsonValue::Array(arr) = parsed + { + for j in arr.iter() { + if let Some(up) = UserProfile::from_json(j) { + try_add_user(up).map_err(|error| std::io::Error::other(error.to_string()))?; } } } diff --git a/iota-storage/src/users/user_profile.rs b/iota-storage/src/users/user_profile.rs index 0e15dd2..63f777f 100644 --- a/iota-storage/src/users/user_profile.rs +++ b/iota-storage/src/users/user_profile.rs @@ -67,7 +67,7 @@ impl UserProfile { "username" => self.username.clone(), "public_key" => self.public_key.clone(), "created_at" => self.created_at, - "storage" => used_dir_space(&format!("users/{}", self.user_id.to_string())), + "storage" => used_dir_space(&format!("users/{}", self.user_id)), }; if let Some(d) = &self.display_name { obj["display_name"] = d.clone().into(); @@ -113,7 +113,7 @@ impl UserProfile { pub fn randomize_reset_token(&mut self) -> String { let mut bytes = [0u8; 192]; OsRng.fill(bytes.as_mut()); - let new_token = general_purpose::STANDARD.encode(&bytes); + let new_token = general_purpose::STANDARD.encode(bytes); self.reset_token = Some(new_token.clone()); new_token } diff --git a/iota-storage/src/util/call_envelopes.rs b/iota-storage/src/util/call_envelopes.rs index 497463f..655b839 100644 --- a/iota-storage/src/util/call_envelopes.rs +++ b/iota-storage/src/util/call_envelopes.rs @@ -40,6 +40,7 @@ pub struct CallEnvelope { pub fn store(envelope: &CallEnvelope, now: i64) -> Result { db::with_immediate_transaction(|tx| { tx.execute("DELETE FROM call_envelopes WHERE expires_at <= ?1", [now])?; + #[expect(clippy::type_complexity, reason = "tuple matches the selected database columns")] let existing: Option<(i64, i64, i64, String, i64, Vec, Vec, String)> = tx.query_row( "SELECT owner_omikron_id, inviter_id, created_at, secret_id, version_number, encrypted_secret, kem_ciphertext, wrapping_scheme FROM call_envelopes WHERE recipient_id = ?1 AND call_id = ?2", params![envelope.recipient_id, envelope.call_id], diff --git a/iota-storage/src/util/chat_files.rs b/iota-storage/src/util/chat_files.rs index c697c47..788e1b9 100644 --- a/iota-storage/src/util/chat_files.rs +++ b/iota-storage/src/util/chat_files.rs @@ -30,6 +30,10 @@ impl MessageState { } } + #[expect( + clippy::should_implement_trait, + reason = "unknown stored states fall back rather than fail parsing" + )] pub fn from_str(value: &str) -> Self { match value.to_lowercase().as_str() { "read" => MessageState::Read, @@ -1024,6 +1028,10 @@ pub fn change_message_state_by_relay_id( }) } +#[expect( + clippy::too_many_arguments, + reason = "explicit persisted receipt fields" +)] pub fn record_message_receipt( storage_owner: i64, target_signer_id: i64, @@ -1232,7 +1240,7 @@ pub fn change_message_state( tx.commit()?; Ok(()) }) - .map_err(|e: StorageError| std::io::Error::new(std::io::ErrorKind::Other, e.to_string())) + .map_err(|e: StorageError| std::io::Error::other(e.to_string())) } fn load_reactions( @@ -1275,10 +1283,9 @@ fn load_reactions( if reactions .iter() .any(|stored: &StoredReaction| stored.reaction == row.1.reaction) + || reactions.len() < MAX_UNIQUE_REACTIONS_PER_MESSAGE { reactions.push(row.1); - } else if reactions.len() < MAX_UNIQUE_REACTIONS_PER_MESSAGE { - reactions.push(row.1); } } Ok(map) diff --git a/iota-storage/src/util/config_util.rs b/iota-storage/src/util/config_util.rs index 51e2e5f..85ad164 100644 --- a/iota-storage/src/util/config_util.rs +++ b/iota-storage/src/util/config_util.rs @@ -127,16 +127,13 @@ pub struct RelayRouterSettings { #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(rename_all = "snake_case")] +#[derive(Default)] pub enum WebMode { + #[default] Disabled, Loopback, Network, } -impl Default for WebMode { - fn default() -> Self { - Self::Disabled - } -} #[derive(Debug, Clone, Serialize, Deserialize)] #[serde(deny_unknown_fields)] @@ -340,14 +337,14 @@ pub fn save_config() { pub fn save_config_to(path: &Path) { if let Ok(yaml) = serde_yaml::to_string(&**CONFIG.load()) { - if let Some(parent) = path.parent() { - if let Err(error) = fs::create_dir_all(parent) { - eprintln!( - "Cannot create configuration directory {}: {error}", - parent.display() - ); - return; - } + if let Some(parent) = path.parent() + && let Err(error) = fs::create_dir_all(parent) + { + eprintln!( + "Cannot create configuration directory {}: {error}", + parent.display() + ); + return; } if let Err(error) = iota_util::atomic_file::replace(path, yaml.as_bytes(), 3) { eprintln!("Cannot save {}: {error}", path.display()); @@ -495,8 +492,10 @@ mod tests { #[test] fn zero_ipc_capacity_is_rejected() { - let mut config = IotaConfig::default(); - config.max_ipc_clients = 0; + let config = IotaConfig { + max_ipc_clients: 0, + ..IotaConfig::default() + }; assert!(matches!( validate_config(&config), Err(ConfigError::InvalidMaxIpcClients) diff --git a/iota-storage/src/util/db.rs b/iota-storage/src/util/db.rs index 71a17f4..07b13bf 100644 --- a/iota-storage/src/util/db.rs +++ b/iota-storage/src/util/db.rs @@ -2116,7 +2116,7 @@ where let guard = shared .lock() .map_err(|e| format!("DB mutex poisoned: {:?}", e))?; - f(&*guard).map_err(|e| e.to_string()) + f(&guard).map_err(|e| e.to_string()) }) } diff --git a/iota-storage/src/util/message_storage_policy.rs b/iota-storage/src/util/message_storage_policy.rs index 0d9568f..d6a08b4 100644 --- a/iota-storage/src/util/message_storage_policy.rs +++ b/iota-storage/src/util/message_storage_policy.rs @@ -38,10 +38,10 @@ fn validate(user_id: i64, retention: MessageRetention) -> Result<(), StorageErro "invalid message storage policy owner".into(), )); } - if let MessageRetention::Duration { duration_ms } = retention { - if !(MIN_RETENTION_DURATION_MS..=MAX_RETENTION_DURATION_MS).contains(&duration_ms) { - return Err(StorageError::Other("invalid retention duration".into())); - } + if let MessageRetention::Duration { duration_ms } = retention + && !(MIN_RETENTION_DURATION_MS..=MAX_RETENTION_DURATION_MS).contains(&duration_ms) + { + return Err(StorageError::Other("invalid retention duration".into())); } Ok(()) } diff --git a/iota-storage/src/util/user_blobs.rs b/iota-storage/src/util/user_blobs.rs index 0f0017d..0e50f20 100644 --- a/iota-storage/src/util/user_blobs.rs +++ b/iota-storage/src/util/user_blobs.rs @@ -39,10 +39,10 @@ fn validate(user_id: i64, blob_id: &str, blob: Option<&[u8]>) -> Result<(), Stor if blob_id.is_empty() || blob_id.len() > MAX_BLOB_ID_BYTES { return Err(StorageError::Other("invalid blob id".into())); } - if let Some(blob) = blob { - if blob.len() > MAX_BLOB_BYTES { - return Err(StorageError::Other("blob exceeds size limit".into())); - } + if let Some(blob) = blob + && blob.len() > MAX_BLOB_BYTES + { + return Err(StorageError::Other("blob exceeds size limit".into())); } Ok(()) } diff --git a/iota-terms/src/terms_getter.rs b/iota-terms/src/terms_getter.rs index 75a7150..bd4f4cd 100755 --- a/iota-terms/src/terms_getter.rs +++ b/iota-terms/src/terms_getter.rs @@ -16,12 +16,15 @@ impl Type { Self::PP => "privacy-policy", } } - pub fn to_string(&self) -> String { - match self { - Self::EULA => "End User License Agreement".to_string(), - Self::TOS => "Terms of Service".to_string(), - Self::PP => "Privacy Policy".to_string(), - } +} + +impl std::fmt::Display for Type { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + f.write_str(match self { + Self::EULA => "End User License Agreement", + Self::TOS => "Terms of Service", + Self::PP => "Privacy Policy", + }) } } diff --git a/iota-util/src/file_util.rs b/iota-util/src/file_util.rs index 8d84fbf..5eaac4d 100755 --- a/iota-util/src/file_util.rs +++ b/iota-util/src/file_util.rs @@ -263,10 +263,8 @@ pub fn get_children(path: &str) -> Vec { }; let mut children = Vec::new(); if let Ok(entries) = fs::read_dir(&dir) { - for entry in entries { - if let Ok(entry) = entry { - children.push(entry.file_name().to_string_lossy().to_string()); - } + for entry in entries.flatten() { + children.push(entry.file_name().to_string_lossy().to_string()); } } children @@ -342,11 +340,11 @@ pub fn get_directory_size(directory: &Path) -> u64 { let mut size = 0; for entry in WalkDir::new(directory).into_iter().filter_map(|e| e.ok()) { let path = entry.path(); - if path.is_file() { - if let Ok(metadata) = path.metadata() { - size += path.file_name().unwrap_or(OsStr::new("")).len() as u64; - size += metadata.len(); - } + if path.is_file() + && let Ok(metadata) = path.metadata() + { + size += path.file_name().unwrap_or(OsStr::new("")).len() as u64; + size += metadata.len(); } } size @@ -427,10 +425,9 @@ fn extract_zip_contents_to_folder( let mut file = archive.by_index(i)?; let entry_path = staging_dir.join(file.sanitized_name()); - if i == 0 { - if file.name().ends_with('/') || file.sanitized_name().components().count() == 1 { - first_item_name = Some(file.sanitized_name()); - } + if i == 0 && (file.name().ends_with('/') || file.sanitized_name().components().count() == 1) + { + first_item_name = Some(file.sanitized_name()); } if file.name().ends_with('/') { @@ -461,7 +458,7 @@ fn extract_zip_contents_to_folder( let src = entry.path(); let dest = target_dir.join(entry.file_name()); - if let Err(_) = fs::rename(&src, &dest) { + if fs::rename(&src, &dest).is_err() { if src.is_file() { fs::copy(&src, &dest)?; } else { diff --git a/iota-util/src/mtp_compat.rs b/iota-util/src/mtp_compat.rs index adc47d3..7c7226e 100644 --- a/iota-util/src/mtp_compat.rs +++ b/iota-util/src/mtp_compat.rs @@ -40,6 +40,10 @@ impl RequiredCommunicationFields for CommunicationValue { } } +#[allow( + clippy::wrong_self_convention, + reason = "mirror DataValue accessors on optional borrowed values" +)] pub trait OptionalDataValueExt<'a> { fn as_bool(self) -> Option; fn as_str(self) -> Option<&'a str>; diff --git a/iota/src/cli_args.rs b/iota/src/cli_args.rs index be8a6d0..bbcd2b0 100644 --- a/iota/src/cli_args.rs +++ b/iota/src/cli_args.rs @@ -557,8 +557,8 @@ impl CliInvocation { let parsed = Cli::try_parse_from(std::iter::once("iota".to_owned()).chain(args)).map_err(|error| { match error.kind() { - ErrorKind::DisplayHelp => return "__help__".to_owned(), - ErrorKind::DisplayVersion => return "__version__".to_owned(), + ErrorKind::DisplayHelp => "__help__".to_owned(), + ErrorKind::DisplayVersion => "__version__".to_owned(), _ => error.to_string(), } }); diff --git a/iota/src/daemon_setup_flow.rs b/iota/src/daemon_setup_flow.rs index da490c7..4ea9dca 100644 --- a/iota/src/daemon_setup_flow.rs +++ b/iota/src/daemon_setup_flow.rs @@ -32,7 +32,7 @@ impl Capabilities { let once = self .executable .as_ref() - .and_then(|_| self.socket.as_ref()) + .and(self.socket.as_ref()) .map(|_| ()) .map_err(ToString::to_string); let ui = once.clone(); @@ -72,10 +72,10 @@ pub async fn run( if let Ok(ipc) = IpcClient::connect(&endpoints.local).await { return Ok(ConnectionContext { ipc }); } - if endpoints.system != endpoints.local { - if let Ok(ipc) = IpcClient::connect(&endpoints.system).await { - return Ok(ConnectionContext { ipc }); - } + if endpoints.system != endpoints.local + && let Ok(ipc) = IpcClient::connect(&endpoints.system).await + { + return Ok(ConnectionContext { ipc }); } let options = caps.options(); if !options.iter().any(|o| o.enabled) { diff --git a/iota/src/local_daemon.rs b/iota/src/local_daemon.rs index a83a139..a690b91 100644 --- a/iota/src/local_daemon.rs +++ b/iota/src/local_daemon.rs @@ -32,13 +32,13 @@ impl LocalDaemonGuard { } impl Drop for LocalDaemonGuard { fn drop(&mut self) { - if !self.committed { - if let Some(mut child) = self.child.take() { - let _ = child.start_kill(); - tokio::spawn(async move { - let _ = child.wait().await; - }); - } + if !self.committed + && let Some(mut child) = self.child.take() + { + let _ = child.start_kill(); + tokio::spawn(async move { + let _ = child.wait().await; + }); } } } diff --git a/iota/src/main.rs b/iota/src/main.rs index 42563a8..fa7cd5a 100644 --- a/iota/src/main.rs +++ b/iota/src/main.rs @@ -1208,7 +1208,7 @@ fn render_table(payload: &ResponsePayload) { println!( "{:<15} {}", "Authority", - format!("{:?}", invitation.authority) + format_args!("{:?}", invitation.authority) ); println!("{:<15} {}", "Token", invitation.raw_token.0); println!("{:<15} {}", "Expires", invitation.expires_at); @@ -1298,8 +1298,8 @@ fn render_table(payload: &ResponsePayload) { println!("No active tasks."); return; } - println!("{}", "NAME"); - println!("{}", "--------"); + println!("NAME"); + println!("--------"); for task in tasks { println!("{}", task.name); } @@ -1309,8 +1309,8 @@ fn render_table(payload: &ResponsePayload) { println!("No component health data available."); return; } - println!("{:<20} {:<10} {}", "COMPONENT", "STATUS", "MESSAGE"); - println!("{:<20} {:<10} {}", "--------", "--------", "--------"); + println!("{:<20} {:<10} MESSAGE", "COMPONENT", "STATUS"); + println!("{:<20} {:<10} --------", "--------", "--------"); for comp in components { let status_str = match comp.status { iota_ipc::HealthStatus::Healthy => "healthy", @@ -1331,8 +1331,8 @@ fn render_table(payload: &ResponsePayload) { println!("No communities."); return; } - println!("{:<20} {}", "NAME", "TITLE"); - println!("{:<20} {}", "--------", "--------"); + println!("{:<20} TITLE", "NAME"); + println!("{:<20} --------", "--------"); for c in communities { println!("{:<20} {}", c.name, c.title); } @@ -1343,12 +1343,12 @@ fn render_table(payload: &ResponsePayload) { return; } println!( - "{:<20} {:<6} {:<12} {}", - "TIMESTAMP", "LEVEL", "SENDER", "MESSAGE" + "{:<20} {:<6} {:<12} MESSAGE", + "TIMESTAMP", "LEVEL", "SENDER" ); println!( - "{:<20} {:<6} {:<12} {}", - "--------", "--------", "--------", "--------" + "{:<20} {:<6} {:<12} --------", + "--------", "--------", "--------" ); for entry in &logs.entries { let level = if entry.is_error { "ERR" } else { "INF" }; @@ -1359,8 +1359,8 @@ fn render_table(payload: &ResponsePayload) { } } ResponsePayload::Status(status) => { - println!("{:<15} {}", "Field", "Value"); - println!("{:<15} {}", "--------", "--------"); + println!("{:<15} Value", "Field"); + println!("{:<15} --------", "--------"); println!("{:<15} {}", "Phase", status.phase); if !status.tasks.is_empty() { println!("{:<15} {}", "Tasks", status.tasks.join(", ")); @@ -1376,16 +1376,16 @@ fn render_table(payload: &ResponsePayload) { println!("{}", config.yaml); } ResponsePayload::OmikronStatus(status) => { - println!("{:<15} {}", "Field", "Value"); - println!("{:<15} {}", "--------", "--------"); + println!("{:<15} Value", "Field"); + println!("{:<15} --------", "--------"); println!("{:<15} {}", "Connected", status.connected); if let Some(id) = &status.iota_id { println!("{:<15} {}", "Iota ID", id); } } ResponsePayload::UpdateStatus(status) => { - println!("{:<15} {}", "Field", "Value"); - println!("{:<15} {}", "--------", "--------"); + println!("{:<15} Value", "Field"); + println!("{:<15} --------", "--------"); println!("{:<15} {}", "Available", status.available); } ResponsePayload::UserCreated { user_id, username } => { @@ -1428,8 +1428,8 @@ fn render_table(payload: &ResponsePayload) { println!("{}", message); } ResponsePayload::UserDetail(user) => { - println!("{:<15} {}", "Field", "Value"); - println!("{:<15} {}", "--------", "--------"); + println!("{:<15} Value", "Field"); + println!("{:<15} --------", "--------"); println!("{:<15} {}", "Username", user.username); println!("{:<15} {}", "User ID", user.user_id); if let Some(ref name) = user.display_name { diff --git a/iota/src/terms.rs b/iota/src/terms.rs index d88464c..65e16b9 100644 --- a/iota/src/terms.rs +++ b/iota/src/terms.rs @@ -73,11 +73,11 @@ async fn accept(system: bool) -> Result<(), StartupError> { for document in [&documents.0, &documents.1, &documents.2] { println!( "\n===== {} =====\nVersion: {}\nDocument hash: {}\n", - document.kind().to_string(), + document.kind(), document.version(), document.hash() ); - print!("{}\n", document.content()); + println!("{}", document.content()); if !confirm(document)? { return Err(StartupError::Consent( "No terms were accepted. Iota remains inactive.".into(), diff --git a/omikron-connector/src/omikron_connection.rs b/omikron-connector/src/omikron_connection.rs index 9dbf5be..8a4aff3 100644 --- a/omikron-connector/src/omikron_connection.rs +++ b/omikron-connector/src/omikron_connection.rs @@ -1,3 +1,8 @@ +#![allow( + clippy::result_large_err, + reason = "return protocol error frames directly to the sender" +)] + use base64::{Engine as _, engine::general_purpose::STANDARD}; use dashmap::{DashMap, DashSet}; use iota_logger::{LogLevel, PrintType, log, log_cv_in, log_cv_out, log_event, log_t}; @@ -350,7 +355,7 @@ pub struct WaitingTask { pub inserted_at: Instant, } -pub static WAITING_TASKS: LazyLock> = LazyLock::new(|| DashMap::new()); +pub static WAITING_TASKS: LazyLock> = LazyLock::new(DashMap::new); pub fn start_task_cleanup_loop() { tokio::spawn(async { @@ -960,7 +965,7 @@ impl OmikronConnection { let conf = CONFIG.load(); match (&conf.omikron_id, &conf.omikron_host, conf.omikron_port) { (Some(id), Some(host), Some(port)) if !host.trim().is_empty() && port != 0 => { - mtp::files::load_public_key_bundle(&omikron_public_key_path(*id)) + mtp::files::load_public_key_bundle(omikron_public_key_path(*id)) .ok() .map(|public_key| ResolvedOmikronEndpoint { id: Some(*id), @@ -1100,10 +1105,10 @@ impl OmikronConnection { }); continue; }; - if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) { - if (task.task)(cv.clone()) { - continue; - } + if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) + && (task.task)(cv.clone()) + { + continue; } let permit = self.handler_semaphore.clone().acquire_owned().await; let self_clone = self.clone(); @@ -1604,8 +1609,7 @@ impl OmikronConnection { Ok(response) if !response.is_type(CommunicationType::ErrorInternal) => { if let (Some(message_id), Some(signer_id)) = (record.relay_message_id.as_deref(), record.relay_signer_id) - { - if let Err(error) = + && let Err(error) = iota_storage::util::downstream_relay::reject_iota_delivery( record.frame_id, signer_principal, @@ -1620,7 +1624,6 @@ impl OmikronConnection { error ); } - } } Ok(response) => log!( "Pending Relay {} route returned retryable {}", @@ -1701,10 +1704,10 @@ impl OmikronConnection { return; }; - if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) { - if (task.task)(cv.clone()) { - return; - } + if let Some((_, task)) = WAITING_TASKS.remove(&msg_id) + && (task.task)(cv.clone()) + { + return; } self.clone().handle_message_impl(cv).await; @@ -1916,15 +1919,14 @@ impl OmikronConnection { if matches!( result, Ok(iota_storage::users::invitations::ProvisioningResult::MissingInvitation) - ) { - if self.sync_omega_invitations().await.is_ok() { - result = iota_storage::users::invitations::apply_external_invitation_provisioning( - invitation_id, - invitation_revision, - &profile, - now, - ); - } + ) && self.sync_omega_invitations().await.is_ok() + { + result = iota_storage::users::invitations::apply_external_invitation_provisioning( + invitation_id, + invitation_revision, + &profile, + now, + ); } match result { Ok( @@ -2378,7 +2380,7 @@ impl OmikronConnection { let port = config .omikron_port .ok_or_else(|| "Omikron port is unavailable".to_string())?; - let omikron_key = mtp::files::load_public_key_bundle(&omikron_public_key_path(omikron_id)) + let omikron_key = mtp::files::load_public_key_bundle(omikron_public_key_path(omikron_id)) .map_err(|error| error.to_string())?; let omikron_public_key = omikron_key .try_to_base64() @@ -3150,11 +3152,7 @@ impl OmikronConnection { } async fn handle_call_envelope_store(self: Arc, cv: &CommunicationValue) { - let response = match CONFIG - .load() - .omikron_id - .and_then(|id| i64::try_from(id).ok()) - { + let response = match CONFIG.load().omikron_id { Some(owner) => message_handlers::handle_call_envelope_store(cv, owner), None => error_response(cv, CommunicationType::ErrorInternal), }; @@ -3162,11 +3160,7 @@ impl OmikronConnection { } async fn handle_call_envelope_get(self: Arc, cv: &CommunicationValue) { - let response = match CONFIG - .load() - .omikron_id - .and_then(|id| i64::try_from(id).ok()) - { + let response = match CONFIG.load().omikron_id { Some(owner) => message_handlers::handle_call_envelope_get(cv, owner), None => error_response(cv, CommunicationType::ErrorInternal), }; diff --git a/omikron-connector/src/password/protected.rs b/omikron-connector/src/password/protected.rs index b0bb6ff..46f8642 100644 --- a/omikron-connector/src/password/protected.rs +++ b/omikron-connector/src/password/protected.rs @@ -121,6 +121,7 @@ impl OmikronConnection { ) } + #[expect(clippy::too_many_arguments, reason = "explicit protected frame fields")] pub(super) fn build_protected( &self, frame: &CommunicationValue, diff --git a/omikron-connector/src/password/runtime.rs b/omikron-connector/src/password/runtime.rs index a6cf5e4..1a93a5a 100644 --- a/omikron-connector/src/password/runtime.rs +++ b/omikron-connector/src/password/runtime.rs @@ -79,10 +79,10 @@ impl AttemptLease { impl Drop for AttemptLease { fn drop(&mut self) { - if !self.settled { - if let Some(runtime) = self.runtime.upgrade() { - runtime.finish_attempt_cancel(self.user_id); - } + if !self.settled + && let Some(runtime) = self.runtime.upgrade() + { + runtime.finish_attempt_cancel(self.user_id); } } } @@ -219,10 +219,10 @@ impl PasswordAuthRuntime { }) .collect::>(); for id in expired { - if let Some((_, pending)) = self.logins.remove(&id) { - if let Some(attempt) = pending.attempt { - attempt.failure(); - } + if let Some((_, pending)) = self.logins.remove(&id) + && let Some(attempt) = pending.attempt + { + attempt.failure(); } } self.enrollments @@ -311,10 +311,10 @@ impl PasswordAuthRuntime { .filter_map(|entry| (entry.user_id == user_id).then_some(*entry.key())) .collect::>(); for id in ids { - if let Some((_, pending)) = self.logins.remove(&id) { - if let Some(attempt) = pending.attempt { - attempt.cancel(); - } + if let Some((_, pending)) = self.logins.remove(&id) + && let Some(attempt) = pending.attempt + { + attempt.cancel(); } } } diff --git a/omikron-connector/src/user_ops.rs b/omikron-connector/src/user_ops.rs index b935087..b04d7ec 100644 --- a/omikron-connector/src/user_ops.rs +++ b/omikron-connector/src/user_ops.rs @@ -386,15 +386,15 @@ pub async fn reconcile_managed_users(connection: &dyn OmikronClient) { let _ = pending_operations::remove(operation.user_id); } } - PendingUserOperationKind::Release if remote_iota_id != Some(local_iota_id) => { - if iota_storage::users::user_manager::finalize_local_release( - operation.user_id, - Some(&operation.username), - ) - .is_ok() - { - let _ = pending_operations::remove(operation.user_id); - } + PendingUserOperationKind::Release + if remote_iota_id != Some(local_iota_id) + && iota_storage::users::user_manager::finalize_local_release( + operation.user_id, + Some(&operation.username), + ) + .is_ok() => + { + let _ = pending_operations::remove(operation.user_id); } _ => {} } @@ -425,17 +425,17 @@ pub async fn reconcile_managed_users(connection: &dyn OmikronClient) { continue; } }; - if should_release { - if let Err(error) = iota_storage::users::user_manager::finalize_local_release( + if should_release + && let Err(error) = iota_storage::users::user_manager::finalize_local_release( user.user_id, Some(&user.username), - ) { - log!( - "Could not release local user {} after Omega reconciliation: {}", - user.user_id, - error - ); - } + ) + { + log!( + "Could not release local user {} after Omega reconciliation: {}", + user.user_id, + error + ); } } } @@ -598,7 +598,7 @@ pub async fn create_user( let mut bytes = [0u8; 192]; OsRng.fill_bytes(&mut bytes); - let reset_token = STANDARD.encode(&bytes); + let reset_token = STANDARD.encode(bytes); let user_profile = UserProfile::new( user_id,