diff --git a/src/action/base/add_user_to_group.rs b/src/action/base/add_user_to_group.rs index bf88b37..2b570d7 100644 --- a/src/action/base/add_user_to_group.rs +++ b/src/action/base/add_user_to_group.rs @@ -111,7 +111,6 @@ impl AddUserToGroup { this.groupname ); // The group will be created by the installer - () }, _ => { // Some other issue @@ -131,7 +130,7 @@ impl AddUserToGroup { .await .map_err(Self::error)?; let output_str = String::from_utf8(output.stdout).map_err(Self::error)?; - let user_in_group = output_str.split(" ").any(|v| v == &this.groupname); + let user_in_group = output_str.split(' ').any(|v| v == this.groupname); if user_in_group { tracing::debug!( diff --git a/src/action/base/create_or_merge_nix_config.rs b/src/action/base/create_or_merge_nix_config.rs index 75c4411..250ac0b 100644 --- a/src/action/base/create_or_merge_nix_config.rs +++ b/src/action/base/create_or_merge_nix_config.rs @@ -35,9 +35,9 @@ pub enum CreateOrMergeNixConfigError { UnmergeableConfig(Vec, std::path::PathBuf), } -impl Into for CreateOrMergeNixConfigError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: CreateOrMergeNixConfigError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } @@ -164,7 +164,7 @@ impl CreateOrMergeNixConfig { .map_err(Self::error)?; let (merged_nix_config, existing_nix_config) = Self::merge_pending_and_existing_nix_config( - &pending_nix_config, + pending_nix_config, &existing_nix_config, &path, ) @@ -273,7 +273,7 @@ impl Action for CreateOrMergeNixConfig { let (mut merged_nix_config, mut existing_nix_config) = if path.exists() { let (merged_nix_config, existing_nix_config) = - Self::validate_existing_nix_config(&pending_nix_config, &path)?; + Self::validate_existing_nix_config(pending_nix_config, path)?; (merged_nix_config, Some(existing_nix_config)) } else { (pending_nix_config.clone(), None) @@ -342,7 +342,7 @@ impl Action for CreateOrMergeNixConfig { // standalone comments to preserve, but no settings with inline comments. if setting_line.is_empty() { for line in &line_group { - new_config.push_str(&line); + new_config.push_str(line); new_config.push('\n'); } @@ -624,20 +624,19 @@ mod test { .settings_mut() .insert("warn-dirty".into(), "false".into()); match CreateOrMergeNixConfig::plan(&test_file, nix_config).await { - Err(err) => match err.kind() { - ActionErrorKind::Custom(e) => { + Err(err) => { + if let ActionErrorKind::Custom(e) = err.kind() { match e.downcast_ref::() { Some(CreateOrMergeNixConfigError::UnmergeableConfig(_, path)) => { assert_eq!(path, test_file.as_path()) }, _ => { return Err(eyre!( - "Should have returned CreateOrMergeNixConfigError::UnmergeableConfig" - )) + "Should have returned CreateOrMergeNixConfigError::UnmergeableConfig" + )) }, } - }, - _ => (), + } }, _ => { return Err(eyre!( diff --git a/src/action/base/create_user.rs b/src/action/base/create_user.rs index 791aa05..f857f22 100644 --- a/src/action/base/create_user.rs +++ b/src/action/base/create_user.rs @@ -211,7 +211,7 @@ impl Action for CreateUser { "--home-dir", "/var/empty", "--comment", - &comment, + comment, "--gid", &gid.to_string(), "--groups", @@ -238,7 +238,7 @@ impl Action for CreateUser { "--home", "/var/empty", "--gecos", - &comment, + comment, "--ingroup", groupname, "--system", diff --git a/src/action/base/fetch_and_unpack_nix.rs b/src/action/base/fetch_and_unpack_nix.rs index 69c6fd0..9ab9555 100644 --- a/src/action/base/fetch_and_unpack_nix.rs +++ b/src/action/base/fetch_and_unpack_nix.rs @@ -44,7 +44,7 @@ impl FetchAndUnpackNix { } if let Some(ssl_cert_file) = &ssl_cert_file { - parse_ssl_cert(&ssl_cert_file).await.map_err(Self::error)?; + parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?; } Ok(Self { @@ -105,7 +105,7 @@ impl Action for FetchAndUnpackNix { ) } if let Some(ssl_cert_file) = &self.ssl_cert_file { - let ssl_cert = parse_ssl_cert(&ssl_cert_file).await.map_err(Self::error)?; + let ssl_cert = parse_ssl_cert(ssl_cert_file).await.map_err(Self::error)?; buildable_client = buildable_client.add_root_certificate(ssl_cert); } let client = buildable_client @@ -181,8 +181,8 @@ pub enum FetchUrlError { UnknownProxyScheme, } -impl Into for FetchUrlError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: FetchUrlError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/base/move_unpacked_nix.rs b/src/action/base/move_unpacked_nix.rs index 9e93253..875e390 100644 --- a/src/action/base/move_unpacked_nix.rs +++ b/src/action/base/move_unpacked_nix.rs @@ -50,7 +50,7 @@ impl Action for MoveUnpackedNix { fn execute_description(&self) -> Vec { vec![ActionDescription::new( - format!("Move the downloaded Nix into `/nix`"), + "Move the downloaded Nix into `/nix`".to_string(), vec![format!( "Nix is being downloaded to `{}` and should be in `/nix`", self.unpacked_path.display(), @@ -107,9 +107,7 @@ impl Action for MoveUnpackedNix { tracing::trace!(src = %entry.path().display(), dest = %entry_dest.display(), "Renaming"); tokio::fs::rename(&entry.path(), &entry_dest) .await - .map_err(|e| { - ActionErrorKind::Rename(entry.path().clone(), entry_dest.to_owned(), e) - }) + .map_err(|e| ActionErrorKind::Rename(entry.path(), entry_dest.to_owned(), e)) .map_err(Self::error)?; let perms: Permissions = PermissionsExt::from_mode(0o555); @@ -134,9 +132,7 @@ impl Action for MoveUnpackedNix { // eg, know which `nix` version we installed when curing a user with several versions installed tokio::fs::symlink(&entry_dest, entry.path()) .await - .map_err(|e| { - ActionErrorKind::Symlink(entry_dest.to_owned(), entry.path().clone(), e) - }) + .map_err(|e| ActionErrorKind::Symlink(entry_dest.to_owned(), entry.path(), e)) .map_err(Self::error)?; } @@ -171,8 +167,8 @@ pub enum MoveUnpackedNixError { ), } -impl Into for MoveUnpackedNixError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: MoveUnpackedNixError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/base/remove_directory.rs b/src/action/base/remove_directory.rs index 382aaf1..32e7c80 100644 --- a/src/action/base/remove_directory.rs +++ b/src/action/base/remove_directory.rs @@ -19,9 +19,7 @@ impl RemoveDirectory { let path = path.as_ref().to_path_buf(); Ok(StatefulAction { - action: Self { - path: path.to_path_buf(), - }, + action: Self { path }, state: ActionState::Uncompleted, }) } diff --git a/src/action/base/setup_default_profile.rs b/src/action/base/setup_default_profile.rs index 4bf504c..6a67cd3 100644 --- a/src/action/base/setup_default_profile.rs +++ b/src/action/base/setup_default_profile.rs @@ -54,7 +54,7 @@ impl Action for SetupDefaultProfile { // Find an `nix` package let nix_pkg_glob = format!("{}/nix-*/store/*-nix-*.*.*", self.unpacked_path.display()); let mut found_nix_pkg = None; - for entry in glob(&nix_pkg_glob).map_err(|e| Self::error(e))? { + for entry in glob(&nix_pkg_glob).map_err(Self::error)? { match entry { Ok(path) => { // If we are curing, the user may have multiple of these installed @@ -83,7 +83,7 @@ impl Action for SetupDefaultProfile { self.unpacked_path.display() ); let mut found_nss_ca_cert_pkg = None; - for entry in glob(&nss_ca_cert_pkg_glob).map_err(|e| Self::error(e))? { + for entry in glob(&nss_ca_cert_pkg_glob).map_err(Self::error)? { match entry { Ok(path) => { // If we are curing, the user may have multiple of these installed @@ -109,14 +109,14 @@ impl Action for SetupDefaultProfile { }; let found_nix_paths = glob::glob(&format!("{}/nix-*", self.unpacked_path.display())) - .map_err(|e| Self::error(e))? + .map_err(Self::error)? .collect::, _>>() - .map_err(|e| Self::error(e))?; + .map_err(Self::error)?; if found_nix_paths.len() != 1 { return Err(Self::error(ActionErrorKind::MalformedBinaryTarball)); } let found_nix_path = found_nix_paths.into_iter().next().unwrap(); - let reginfo_path = PathBuf::from(found_nix_path).join(".reginfo"); + let reginfo_path = found_nix_path.join(".reginfo"); let reginfo = tokio::fs::read(®info_path) .await .map_err(|e| ActionErrorKind::Read(reginfo_path.to_path_buf(), e)) @@ -248,8 +248,8 @@ pub enum SetupDefaultProfileError { MultipleNixPackages, } -impl Into for SetupDefaultProfileError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: SetupDefaultProfileError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/common/configure_init_service.rs b/src/action/common/configure_init_service.rs index 2a1cf5c..71a3536 100644 --- a/src/action/common/configure_init_service.rs +++ b/src/action/common/configure_init_service.rs @@ -402,18 +402,14 @@ impl Action for ConfigureInitService { // We separate stop and disable (instead of using `--now`) to avoid cases where the service isn't started, but is enabled. // These have to fail fast. - let socket_is_active = is_active("nix-daemon.socket") - .await - .map_err(|e| Self::error(e))?; - let socket_is_enabled = is_enabled("nix-daemon.socket") - .await - .map_err(|e| Self::error(e))?; - let service_is_active = is_active("nix-daemon.service") - .await - .map_err(|e| Self::error(e))?; + let socket_is_active = is_active("nix-daemon.socket").await.map_err(Self::error)?; + let socket_is_enabled = + is_enabled("nix-daemon.socket").await.map_err(Self::error)?; + let service_is_active = + is_active("nix-daemon.service").await.map_err(Self::error)?; let service_is_enabled = is_enabled("nix-daemon.service") .await - .map_err(|e| Self::error(e))?; + .map_err(Self::error)?; if socket_is_active { if let Err(err) = execute_command( diff --git a/src/action/common/create_nix_tree.rs b/src/action/common/create_nix_tree.rs index 12efb7a..f35022e 100644 --- a/src/action/common/create_nix_tree.rs +++ b/src/action/common/create_nix_tree.rs @@ -65,7 +65,7 @@ impl Action for CreateNixTree { let mut create_directory_descriptions = Vec::new(); for create_directory in create_directories { - if let Some(val) = create_directory.describe_execute().iter().next() { + if let Some(val) = create_directory.describe_execute().first() { create_directory_descriptions.push(val.description.clone()) } } @@ -87,7 +87,7 @@ impl Action for CreateNixTree { fn revert_description(&self) -> Vec { vec![ActionDescription::new( - format!("Remove the directory tree in `/nix`"), + "Remove the directory tree in `/nix`".to_string(), vec![ format!( "Nix and the Nix daemon require a Nix Store, which will be stored at `/nix`" diff --git a/src/action/common/create_users_and_groups.rs b/src/action/common/create_users_and_groups.rs index e388aaf..251c019 100644 --- a/src/action/common/create_users_and_groups.rs +++ b/src/action/common/create_users_and_groups.rs @@ -110,14 +110,14 @@ impl Action for CreateUsersAndGroups { let mut create_users_descriptions = Vec::new(); for create_user in create_users { - if let Some(val) = create_user.describe_execute().iter().next() { + if let Some(val) = create_user.describe_execute().first() { create_users_descriptions.push(val.description.clone()) } } let mut add_user_to_group_descriptions = Vec::new(); for add_user_to_group in add_users_to_groups { - if let Some(val) = add_user_to_group.describe_execute().iter().next() { + if let Some(val) = add_user_to_group.describe_execute().first() { add_user_to_group_descriptions.push(val.description.clone()) } } @@ -125,7 +125,7 @@ impl Action for CreateUsersAndGroups { let mut explanation = vec![ format!("The Nix daemon requires system users (and a group they share) which it can act as in order to build"), ]; - if let Some(val) = create_group.describe_execute().iter().next() { + if let Some(val) = create_group.describe_execute().first() { explanation.push(val.description.clone()) } explanation.append(&mut create_users_descriptions); @@ -222,14 +222,14 @@ impl Action for CreateUsersAndGroups { } = &self; let mut create_users_descriptions = Vec::new(); for create_user in create_users { - if let Some(val) = create_user.describe_revert().iter().next() { + if let Some(val) = create_user.describe_revert().first() { create_users_descriptions.push(val.description.clone()) } } let mut add_user_to_group_descriptions = Vec::new(); for add_user_to_group in add_users_to_groups { - if let Some(val) = add_user_to_group.describe_revert().iter().next() { + if let Some(val) = add_user_to_group.describe_revert().first() { add_user_to_group_descriptions.push(val.description.clone()) } } @@ -237,7 +237,7 @@ impl Action for CreateUsersAndGroups { let mut explanation = vec![ format!("The Nix daemon requires system users (and a group they share) which it can act as in order to build"), ]; - if let Some(val) = create_group.describe_revert().iter().next() { + if let Some(val) = create_group.describe_revert().first() { explanation.push(val.description.clone()) } explanation.append(&mut create_users_descriptions); @@ -245,12 +245,12 @@ impl Action for CreateUsersAndGroups { if create_users.is_empty() { vec![ActionDescription::new( - format!("Remove Nix group"), + "Remove Nix group".to_string(), explanation, )] } else { vec![ActionDescription::new( - format!("Remove Nix users and group"), + "Remove Nix users and group".to_string(), explanation, )] } diff --git a/src/action/common/delete_users.rs b/src/action/common/delete_users.rs index 81bb426..79ea22f 100644 --- a/src/action/common/delete_users.rs +++ b/src/action/common/delete_users.rs @@ -58,7 +58,7 @@ impl Action for DeleteUsersInGroup { fn execute_description(&self) -> Vec { let mut delete_users_descriptions = Vec::new(); for delete_user in self.delete_users.iter() { - if let Some(val) = delete_user.describe_execute().iter().next() { + if let Some(val) = delete_user.describe_execute().first() { delete_users_descriptions.push(val.description.clone()) } } @@ -82,7 +82,7 @@ impl Action for DeleteUsersInGroup { fn revert_description(&self) -> Vec { let mut delete_users_descriptions = Vec::new(); for delete_user in self.delete_users.iter() { - if let Some(val) = delete_user.describe_revert().iter().next() { + if let Some(val) = delete_user.describe_revert().first() { delete_users_descriptions.push(val.description.clone()) } } diff --git a/src/action/common/place_nix_configuration.rs b/src/action/common/place_nix_configuration.rs index 39fb587..69502ac 100644 --- a/src/action/common/place_nix_configuration.rs +++ b/src/action/common/place_nix_configuration.rs @@ -47,7 +47,7 @@ impl PlaceNixConfiguration { } }, Entry::Vacant(slot) => { - let _ = slot.insert(experimental_features.join(" ").to_string()); + let _ = slot.insert(experimental_features.join(" ")); }, }; @@ -117,7 +117,7 @@ impl Action for PlaceNixConfiguration { .to_string(), ]; - if let Some(val) = create_directory.describe_execute().iter().next() { + if let Some(val) = create_directory.describe_execute().first() { explanation.push(val.description.clone()) } for val in create_or_merge_nix_config.describe_execute().iter() { diff --git a/src/action/linux/ensure_steamos_nix_directory.rs b/src/action/linux/ensure_steamos_nix_directory.rs index ce39767..1cac2b2 100644 --- a/src/action/linux/ensure_steamos_nix_directory.rs +++ b/src/action/linux/ensure_steamos_nix_directory.rs @@ -42,7 +42,7 @@ impl Action for EnsureSteamosNixDirectory { ActionTag("ensure_steamos_nix_directory") } fn tracing_synopsis(&self) -> String { - format!("Ensure SteamOS's `/nix` directory exists") + "Ensure SteamOS's `/nix` directory exists".to_string() } fn tracing_span(&self) -> Span { diff --git a/src/action/linux/provision_selinux.rs b/src/action/linux/provision_selinux.rs index b7ea34a..fee5c25 100644 --- a/src/action/linux/provision_selinux.rs +++ b/src/action/linux/provision_selinux.rs @@ -37,7 +37,7 @@ impl Action for ProvisionSelinux { ActionTag("provision_selinux") } fn tracing_synopsis(&self) -> String { - format!("Install an SELinux Policy for Nix") + "Install an SELinux Policy for Nix".to_string() } fn tracing_span(&self) -> Span { diff --git a/src/action/linux/revert_clean_steamos_nix_offload.rs b/src/action/linux/revert_clean_steamos_nix_offload.rs index b64479f..deaad8d 100644 --- a/src/action/linux/revert_clean_steamos_nix_offload.rs +++ b/src/action/linux/revert_clean_steamos_nix_offload.rs @@ -6,7 +6,7 @@ use crate::action::{ActionError, ActionErrorKind, ActionTag}; use crate::action::{Action, ActionDescription, StatefulAction}; -const OFFLOAD_PATH: &'static str = "/home/.steamos/offload/nix"; +const OFFLOAD_PATH: &str = "/home/.steamos/offload/nix"; /** Clean out the `/home/.steamos/offload/nix` @@ -71,7 +71,7 @@ impl Action for RevertCleanSteamosNixOffload { tracing::trace!(path = %path.display(), "Removing"); tokio::fs::remove_dir_all(&path) .await - .map_err(|e| Self::error(ActionErrorKind::Remove(path.into(), e)))?; + .map_err(|e| Self::error(ActionErrorKind::Remove(path, e)))?; } Ok(()) diff --git a/src/action/linux/start_systemd_unit.rs b/src/action/linux/start_systemd_unit.rs index b1f9fa8..628206e 100644 --- a/src/action/linux/start_systemd_unit.rs +++ b/src/action/linux/start_systemd_unit.rs @@ -81,7 +81,7 @@ impl Action for StartSystemdUnit { .process_group(0) .arg("enable") .arg("--now") - .arg(format!("{unit}")) + .arg(&unit) .stdin(std::process::Stdio::null()), ) .await @@ -93,7 +93,7 @@ impl Action for StartSystemdUnit { Command::new("systemctl") .process_group(0) .arg("start") - .arg(format!("{unit}")) + .arg(&unit) .stdin(std::process::Stdio::null()), ) .await @@ -120,7 +120,7 @@ impl Action for StartSystemdUnit { Command::new("systemctl") .process_group(0) .arg("disable") - .arg(format!("{}", self.unit)) + .arg(&self.unit) .stdin(std::process::Stdio::null()), ) .await @@ -135,7 +135,7 @@ impl Action for StartSystemdUnit { Command::new("systemctl") .process_group(0) .arg("stop") - .arg(format!("{}", self.unit)) + .arg(&self.unit) .stdin(std::process::Stdio::null()), ) .await diff --git a/src/action/linux/systemctl_daemon_reload.rs b/src/action/linux/systemctl_daemon_reload.rs index 4286640..3bfce35 100644 --- a/src/action/linux/systemctl_daemon_reload.rs +++ b/src/action/linux/systemctl_daemon_reload.rs @@ -36,7 +36,7 @@ impl Action for SystemctlDaemonReload { ActionTag("systemctl_daemon_reload") } fn tracing_synopsis(&self) -> String { - format!("Run `systemctl daemon-reload`") + "Run `systemctl daemon-reload`".to_string() } fn tracing_span(&self) -> Span { diff --git a/src/action/macos/bootstrap_launchctl_service.rs b/src/action/macos/bootstrap_launchctl_service.rs index c882a10..b019c98 100644 --- a/src/action/macos/bootstrap_launchctl_service.rs +++ b/src/action/macos/bootstrap_launchctl_service.rs @@ -47,11 +47,7 @@ impl BootstrapLaunchctlService { .await .map_err(|e| Self::error(ActionErrorKind::command(&command, e)))?; // We presume that success means it's found - if command_output.status.success() || command_output.status.code() == Some(37) { - true - } else { - false - } + command_output.status.success() || command_output.status.code() == Some(37) }; let is_disabled = service_is_disabled(&domain, &service) diff --git a/src/action/macos/create_fstab_entry.rs b/src/action/macos/create_fstab_entry.rs index 484136c..8eac221 100644 --- a/src/action/macos/create_fstab_entry.rs +++ b/src/action/macos/create_fstab_entry.rs @@ -122,7 +122,7 @@ impl Action for CreateFstabEntry { existing_entry, } = self; let fstab_path = Path::new(FSTAB_PATH); - let uuid = match get_uuid_for_label(&apfs_volume_label) + let uuid = match get_uuid_for_label(apfs_volume_label) .await .map_err(Self::error)? { @@ -158,7 +158,7 @@ impl Action for CreateFstabEntry { .collect::>(); let mut updated_line = false; let mut saw_prelude = false; - let prelude = fstab_prelude_comment(&apfs_volume_label); + let prelude = fstab_prelude_comment(apfs_volume_label); for line in current_fstab_lines.iter_mut() { if line == &prelude { saw_prelude = true; @@ -306,8 +306,8 @@ pub enum CreateFstabEntryError { CannotDetermineFstabLine, } -impl Into for CreateFstabEntryError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: CreateFstabEntryError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/macos/create_volume_service.rs b/src/action/macos/create_volume_service.rs index ecbf638..fbf2b71 100644 --- a/src/action/macos/create_volume_service.rs +++ b/src/action/macos/create_volume_service.rs @@ -117,7 +117,7 @@ impl CreateVolumeService { .await .map_err(|e| Self::error(ActionErrorKind::Read(fstab, e)))?; for line in contents.lines() { - if line.starts_with("#") { + if line.starts_with('#') { continue; } let split = line.split_whitespace(); @@ -204,7 +204,7 @@ impl Action for CreateVolumeService { } } - let uuid = match get_uuid_for_label(&apfs_volume_label) + let uuid = match get_uuid_for_label(apfs_volume_label) .await .map_err(Self::error)? { @@ -216,8 +216,8 @@ impl Action for CreateVolumeService { }, }; let generated_plist = generate_mount_plist( - &mount_service_label, - &apfs_volume_label, + mount_service_label, + apfs_volume_label, uuid, mount_point, *encrypt, @@ -315,8 +315,8 @@ pub enum CreateVolumeServiceError { VolumeDoesNotExistButVolumeServiceAndFstabEntryDoes(PathBuf, String), } -impl Into for CreateVolumeServiceError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: CreateVolumeServiceError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/macos/enable_ownership.rs b/src/action/macos/enable_ownership.rs index 00353ab..f39e528 100644 --- a/src/action/macos/enable_ownership.rs +++ b/src/action/macos/enable_ownership.rs @@ -104,8 +104,8 @@ pub enum EnableOwnershipError { Command(#[source] std::io::Error), } -impl Into for EnableOwnershipError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: EnableOwnershipError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/macos/encrypt_apfs_volume.rs b/src/action/macos/encrypt_apfs_volume.rs index 87f349d..52db643 100644 --- a/src/action/macos/encrypt_apfs_volume.rs +++ b/src/action/macos/encrypt_apfs_volume.rs @@ -64,13 +64,11 @@ impl EncryptApfsVolume { return Err(Self::error(EncryptApfsVolumeError::ExistingPasswordFound( name, disk, ))); - } else { - if planned_create_apfs_volume.state == ActionState::Completed { - // The user has a volume already created, but a password not set. This means we probably can't decrypt the volume. - return Err(Self::error( - EncryptApfsVolumeError::MissingPasswordForExistingVolume(name, disk), - )); - } + } else if planned_create_apfs_volume.state == ActionState::Completed { + // The user has a volume already created, but a password not set. This means we probably can't decrypt the volume. + return Err(Self::error( + EncryptApfsVolumeError::MissingPasswordForExistingVolume(name, disk), + )); } // Ensure if the disk already exists, that it's encrypted @@ -84,15 +82,12 @@ impl EncryptApfsVolume { for container in parsed.containers { for volume in container.volumes { if volume.name.as_ref() == Some(&name) { - match volume.encryption == false { - true => { - return Ok(StatefulAction::completed(Self { disk, name })); - }, - false => { - return Err(Self::error( - EncryptApfsVolumeError::ExistingVolumeNotEncrypted(name, disk), - )); - }, + if volume.encryption { + return Err(Self::error( + EncryptApfsVolumeError::ExistingVolumeNotEncrypted(name, disk), + )); + } else { + return Ok(StatefulAction::completed(Self { disk, name })); } } } @@ -265,8 +260,8 @@ pub enum EncryptApfsVolumeError { ExistingVolumeNotEncrypted(String, PathBuf), } -impl Into for EncryptApfsVolumeError { - fn into(self) -> ActionErrorKind { - ActionErrorKind::Custom(Box::new(self)) +impl From for ActionErrorKind { + fn from(val: EncryptApfsVolumeError) -> Self { + ActionErrorKind::Custom(Box::new(val)) } } diff --git a/src/action/macos/kickstart_launchctl_service.rs b/src/action/macos/kickstart_launchctl_service.rs index 8cb419a..f6d699c 100644 --- a/src/action/macos/kickstart_launchctl_service.rs +++ b/src/action/macos/kickstart_launchctl_service.rs @@ -43,7 +43,7 @@ impl KickstartLaunchctlService { if output.status.success() { service_exists = true; - let output_string = String::from_utf8(output.stdout).map_err(|e| Self::error(e))?; + let output_string = String::from_utf8(output.stdout).map_err(Self::error)?; // We are looking for a line containing "state = " with some trailing content // The output is not a JSON or a plist // MacOS's man pages explicitly tell us not to try to parse this output diff --git a/src/action/macos/mod.rs b/src/action/macos/mod.rs index 74a49be..d1e5ef4 100644 --- a/src/action/macos/mod.rs +++ b/src/action/macos/mod.rs @@ -55,12 +55,12 @@ async fn get_uuid_for_label(apfs_volume_label: &str) -> Result, Act if let Some(error_message) = parsed.error_message { let expected_not_found = format!("Could not find disk: {apfs_volume_label}"); if error_message.contains(&expected_not_found) { - return Ok(None); + Ok(None) } else { - return Err(ActionErrorKind::DiskUtilInfoError { + Err(ActionErrorKind::DiskUtilInfoError { command: command_str, message: error_message, - }); + }) } } else if let Some(uuid) = parsed.volume_uuid { Ok(Some(uuid)) @@ -86,7 +86,7 @@ pub(crate) async fn service_is_disabled( let output = execute_command( Command::new("launchctl") .arg("print-disabled") - .arg(&domain) + .arg(domain) .stdin(std::process::Stdio::null()) .stdout(std::process::Stdio::piped()) .stderr(std::process::Stdio::piped()), diff --git a/src/action/macos/set_tmutil_exclusions.rs b/src/action/macos/set_tmutil_exclusions.rs index 66b787d..da336e0 100644 --- a/src/action/macos/set_tmutil_exclusions.rs +++ b/src/action/macos/set_tmutil_exclusions.rs @@ -78,7 +78,7 @@ impl Action for SetTmutilExclusions { let mut set_tmutil_exclusion_descriptions = Vec::new(); for set_tmutil_exclusion in set_tmutil_exclusions { - if let Some(val) = set_tmutil_exclusion.describe_execute().iter().next() { + if let Some(val) = set_tmutil_exclusion.describe_execute().first() { set_tmutil_exclusion_descriptions.push(val.description.clone()) } } @@ -103,7 +103,7 @@ impl Action for SetTmutilExclusions { fn revert_description(&self) -> Vec { vec![ActionDescription::new( - format!("Remove time machine exclusions"), + "Remove time machine exclusions".to_string(), vec![], )] } diff --git a/src/action/macos/unmount_apfs_volume.rs b/src/action/macos/unmount_apfs_volume.rs index 9b8a758..e303c6e 100644 --- a/src/action/macos/unmount_apfs_volume.rs +++ b/src/action/macos/unmount_apfs_volume.rs @@ -69,7 +69,7 @@ impl Action for UnmountApfsVolume { .map_err(Self::error)? .stdout; let the_plist: DiskUtilInfoOutput = - plist::from_reader(Cursor::new(buf)).map_err(|e| Self::error(e))?; + plist::from_reader(Cursor::new(buf)).map_err(Self::error)?; the_plist.mount_point.is_some() }; @@ -111,7 +111,7 @@ impl Action for UnmountApfsVolume { .map_err(Self::error)? .stdout; let the_plist: DiskUtilInfoOutput = - plist::from_reader(Cursor::new(buf)).map_err(|e| Self::error(e))?; + plist::from_reader(Cursor::new(buf)).map_err(Self::error)?; the_plist.mount_point.is_some() }; diff --git a/src/action/mod.rs b/src/action/mod.rs index ed9dfd6..d860391 100644 --- a/src/action/mod.rs +++ b/src/action/mod.rs @@ -635,7 +635,7 @@ impl crate::diagnostics::ErrorDiagnostic for ActionErrorKind { }, _ => vec![], }; - return format!( + format!( "{}({})", static_str, context @@ -643,6 +643,6 @@ impl crate::diagnostics::ErrorDiagnostic for ActionErrorKind { .map(|v| format!("\"{v}\"")) .collect::>() .join(", ") - ); + ) } } diff --git a/src/action/stateful.rs b/src/action/stateful.rs index 3a997fa..f8374cd 100644 --- a/src/action/stateful.rs +++ b/src/action/stateful.rs @@ -145,14 +145,14 @@ where if self.state == ActionState::Completed { return vec![]; } - return self.action.execute_description(); + self.action.execute_description() } /// A description of what this action would do during revert pub fn describe_revert(&self) -> Vec { if self.state == ActionState::Uncompleted { return vec![]; } - return self.action.revert_description(); + self.action.revert_description() } /// Perform any execution steps /// diff --git a/src/cli/arg/instrumentation.rs b/src/cli/arg/instrumentation.rs index 239fb55..b7b3413 100644 --- a/src/cli/arg/instrumentation.rs +++ b/src/cli/arg/instrumentation.rs @@ -139,7 +139,7 @@ impl<'a> Instrumentation { } EnvFilter::try_new(&format!( "{}={}", - env!("CARGO_PKG_NAME").replace("-", "_"), + env!("CARGO_PKG_NAME").replace('-', "_"), self.log_level() ))? }, diff --git a/src/cli/mod.rs b/src/cli/mod.rs index 259db50..7f33ea3 100644 --- a/src/cli/mod.rs +++ b/src/cli/mod.rs @@ -123,7 +123,7 @@ pub fn ensure_root() -> eyre::Result<()> { if is_ci::cached() { // Normally `sudo` would erase those envs, so we detect and pass that along specifically to avoid having to pass around // a bunch of environment variables - env_list.push(format!("NIX_INSTALLER_CI=1")); + env_list.push("NIX_INSTALLER_CI=1".to_string()); } if !env_list.is_empty() { diff --git a/src/cli/subcommand/install.rs b/src/cli/subcommand/install.rs index 59e2e3f..aaa18a7 100644 --- a/src/cli/subcommand/install.rs +++ b/src/cli/subcommand/install.rs @@ -24,7 +24,7 @@ use color_eyre::{ }; use owo_colors::OwoColorize; -const EXISTING_INCOMPATIBLE_PLAN_GUIDANCE: &'static str = "\ +const EXISTING_INCOMPATIBLE_PLAN_GUIDANCE: &str = "\ If you are trying to upgrade Nix, try running `sudo -i nix upgrade-nix` instead.\n\ If you are trying to install Nix over an existing install (from an incompatible `nix-installer` install), try running `/nix/nix-installer uninstall` then try to install again.\n\ If you are using `nix-installer` in an automated curing process and seeing this message, consider pinning the version you use via https://github.com/DeterminateSystems/nix-installer#accessing-other-versions.\ diff --git a/src/diagnostics.rs b/src/diagnostics.rs index 18de1cc..1388328 100644 --- a/src/diagnostics.rs +++ b/src/diagnostics.rs @@ -174,14 +174,12 @@ impl DiagnosticData { tracing::debug!("Sending diagnostic to `{endpoint}`"); let mut buildable_client = reqwest::Client::builder(); if let Some(ssl_cert_file) = &self.ssl_cert_file { - let ssl_cert = parse_ssl_cert(&ssl_cert_file).await.ok(); + let ssl_cert = parse_ssl_cert(ssl_cert_file).await.ok(); if let Some(ssl_cert) = ssl_cert { buildable_client = buildable_client.add_root_certificate(ssl_cert); } } - let client = buildable_client - .build() - .map_err(|e| DiagnosticError::Reqwest(e))?; + let client = buildable_client.build().map_err(DiagnosticError::Reqwest)?; let res = client .post(endpoint.clone()) @@ -247,7 +245,7 @@ pub trait ErrorDiagnostic { impl ErrorDiagnostic for DiagnosticError { fn diagnostic(&self) -> String { let static_str: &'static str = (self).into(); - return static_str.to_string(); + static_str.to_string() } } diff --git a/src/error.rs b/src/error.rs index 2d13349..ab8f376 100644 --- a/src/error.rs +++ b/src/error.rs @@ -128,16 +128,16 @@ impl crate::diagnostics::ErrorDiagnostic for NixInstallerError { let context = match self { Self::SelfTest(self_tests) => self_tests .iter() - .map(|self_test| self_test.diagnostic().to_string()) + .map(|self_test| self_test.diagnostic()) .collect::>(), - Self::Action(action_error) => vec![action_error.diagnostic().to_string()], + Self::Action(action_error) => vec![action_error.diagnostic()], Self::ActionRevert(action_errors) => action_errors .iter() - .map(|action_error| action_error.diagnostic().to_string()) + .map(|action_error| action_error.diagnostic()) .collect(), _ => vec![], }; - return format!( + format!( "{}({})", static_str, context @@ -145,6 +145,6 @@ impl crate::diagnostics::ErrorDiagnostic for NixInstallerError { .map(|v| format!("\"{v}\"")) .collect::>() .join(", ") - ); + ) } } diff --git a/src/plan.rs b/src/plan.rs index 14e3d07..62e1809 100644 --- a/src/plan.rs +++ b/src/plan.rs @@ -128,8 +128,7 @@ impl InstallPlan { }, actions = actions .iter() - .map(|v| v.describe_execute()) - .flatten() + .flat_map(|v| v.describe_execute()) .map(|desc| { let ActionDescription { description, @@ -300,8 +299,7 @@ impl InstallPlan { actions = actions .iter() .rev() - .map(|v| v.describe_revert()) - .flatten() + .flat_map(|v| v.describe_revert()) .map(|desc| { let ActionDescription { description, @@ -394,7 +392,7 @@ impl InstallPlan { .await?; } - return Err(error); + Err(error) } } diff --git a/src/planner/linux.rs b/src/planner/linux.rs index 85b8256..66438c7 100644 --- a/src/planner/linux.rs +++ b/src/planner/linux.rs @@ -156,9 +156,9 @@ impl Planner for Linux { } } -impl Into for Linux { - fn into(self) -> BuiltinPlanner { - BuiltinPlanner::Linux(self) +impl From for BuiltinPlanner { + fn from(val: Linux) -> Self { + BuiltinPlanner::Linux(val) } } @@ -196,11 +196,12 @@ pub(crate) async fn detect_selinux() -> Result { pub(crate) async fn check_nix_not_already_installed() -> Result<(), PlannerError> { // For now, we don't try to repair the user's Nix install or anything special. - if let Ok(_) = Command::new("nix-env") + if Command::new("nix-env") .arg("--version") .stdin(std::process::Stdio::null()) .status() .await + .is_ok() { return Err(PlannerError::NixExists); } diff --git a/src/planner/mod.rs b/src/planner/mod.rs index c91bba9..8db515a 100644 --- a/src/planner/mod.rs +++ b/src/planner/mod.rs @@ -443,6 +443,6 @@ impl HasExpectedErrors for PlannerError { impl crate::diagnostics::ErrorDiagnostic for PlannerError { fn diagnostic(&self) -> String { let static_str: &'static str = (self).into(); - return static_str.to_string(); + static_str.to_string() } } diff --git a/src/planner/steam_deck.rs b/src/planner/steam_deck.rs index cc69b4a..10f9efd 100644 --- a/src/planner/steam_deck.rs +++ b/src/planner/steam_deck.rs @@ -179,8 +179,7 @@ impl Planner for SteamDeck { .boxed(), ); - let nix_directory_buf = format!( - "\ + let nix_directory_buf = "\ [Unit]\n\ Description=Create a `/nix` directory to be used for bind mounting\n\ PropagatesStopTo=nix-daemon.service\n\ @@ -202,7 +201,7 @@ impl Planner for SteamDeck { ExecStop=steamos-readonly enable\n\ RemainAfterExit=true\n\ " - ); + .to_string(); let nix_directory_unit = CreateFile::plan( "/etc/systemd/system/nix-directory.service", None, @@ -267,8 +266,7 @@ impl Planner for SteamDeck { actions.push(start_nix_mount.boxed()); } - let ensure_symlinked_units_resolve_buf = format!( - "\ + let ensure_symlinked_units_resolve_buf = "\ [Unit]\n\ Description=Ensure Nix related units which are symlinked resolve\n\ After=nix.mount\n\ @@ -284,7 +282,7 @@ impl Planner for SteamDeck { [Install]\n\ WantedBy=sysinit.target\n\ " - ); + .to_string(); let ensure_symlinked_units_resolve_unit = CreateFile::plan( "/etc/systemd/system/ensure-symlinked-units-resolve.service", None, @@ -422,9 +420,9 @@ impl Planner for SteamDeck { } } -impl Into for SteamDeck { - fn into(self) -> BuiltinPlanner { - BuiltinPlanner::SteamDeck(self) +impl From for BuiltinPlanner { + fn from(val: SteamDeck) -> Self { + BuiltinPlanner::SteamDeck(val) } } @@ -445,8 +443,7 @@ pub(crate) async fn detect_requires_bind_mount() -> Result { let steamos_nix_mount_unit_path = "/usr/lib/systemd/system/nix.mount"; let nix_mount_unit = tokio::fs::read_to_string(steamos_nix_mount_unit_path) .await - .map(|v| Some(v)) - .unwrap_or_else(|_| None); + .ok(); match nix_mount_unit { Some(nix_mount_unit) if nix_mount_unit.contains("What=/home/.steamos/offload/nix") => { diff --git a/src/self_test.rs b/src/self_test.rs index 61552d7..be04dfa 100644 --- a/src/self_test.rs +++ b/src/self_test.rs @@ -35,7 +35,7 @@ impl crate::diagnostics::ErrorDiagnostic for SelfTestError { Self::Command { shell, .. } => vec![shell.to_string()], Self::SystemTime(_) => vec![], }; - return format!( + format!( "{}({})", static_str, context @@ -43,7 +43,7 @@ impl crate::diagnostics::ErrorDiagnostic for SelfTestError { .map(|v| format!("\"{v}\"")) .collect::>() .join(", ") - ); + ) } } diff --git a/src/settings.rs b/src/settings.rs index 748db4f..7770883 100644 --- a/src/settings.rs +++ b/src/settings.rs @@ -372,7 +372,7 @@ async fn linux_detect_systemd_started() -> bool { let mut started = false; if std::path::Path::new("/run/systemd/system").exists() { - started = if tokio::process::Command::new("systemctl") + started = tokio::process::Command::new("systemctl") .arg("status") .stdin(Stdio::null()) .stdout(Stdio::null()) @@ -382,11 +382,6 @@ async fn linux_detect_systemd_started() -> bool { .ok() .map(|exit| exit.success()) .unwrap_or(false) - { - true - } else { - false - } } // TODO: Other inits @@ -509,6 +504,6 @@ pub enum InstallSettingsError { impl crate::diagnostics::ErrorDiagnostic for InstallSettingsError { fn diagnostic(&self) -> String { let static_str: &'static str = (self).into(); - return static_str.to_string(); + static_str.to_string() } }