Fix most clippy warnings (#572)

The only remaining is at `NixInstallerSubcommand`

See https://rust-lang.github.io/rust-clippy/master/index.html#/large_enum_variant
This commit is contained in:
Hofer-Julian 2023-07-17 17:34:46 +02:00 committed by GitHub
parent 79ab8731fa
commit c3fa6e9623
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
39 changed files with 138 additions and 170 deletions

View file

@ -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!(

View file

@ -35,9 +35,9 @@ pub enum CreateOrMergeNixConfigError {
UnmergeableConfig(Vec<String>, std::path::PathBuf),
}
impl Into<ActionErrorKind> for CreateOrMergeNixConfigError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<CreateOrMergeNixConfigError> 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::<CreateOrMergeNixConfigError>() {
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!(

View file

@ -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",

View file

@ -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<ActionErrorKind> for FetchUrlError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<FetchUrlError> for ActionErrorKind {
fn from(val: FetchUrlError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -50,7 +50,7 @@ impl Action for MoveUnpackedNix {
fn execute_description(&self) -> Vec<ActionDescription> {
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<ActionErrorKind> for MoveUnpackedNixError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<MoveUnpackedNixError> for ActionErrorKind {
fn from(val: MoveUnpackedNixError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -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,
})
}

View file

@ -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::<Result<Vec<_>, _>>()
.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(&reginfo_path)
.await
.map_err(|e| ActionErrorKind::Read(reginfo_path.to_path_buf(), e))
@ -248,8 +248,8 @@ pub enum SetupDefaultProfileError {
MultipleNixPackages,
}
impl Into<ActionErrorKind> for SetupDefaultProfileError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<SetupDefaultProfileError> for ActionErrorKind {
fn from(val: SetupDefaultProfileError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -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(

View file

@ -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<ActionDescription> {
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`"

View file

@ -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,
)]
}

View file

@ -58,7 +58,7 @@ impl Action for DeleteUsersInGroup {
fn execute_description(&self) -> Vec<ActionDescription> {
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<ActionDescription> {
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())
}
}

View file

@ -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() {

View file

@ -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 {

View file

@ -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 {

View file

@ -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(())

View file

@ -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

View file

@ -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 {

View file

@ -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)

View file

@ -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::<Vec<String>>();
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<ActionErrorKind> for CreateFstabEntryError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<CreateFstabEntryError> for ActionErrorKind {
fn from(val: CreateFstabEntryError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -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<ActionErrorKind> for CreateVolumeServiceError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<CreateVolumeServiceError> for ActionErrorKind {
fn from(val: CreateVolumeServiceError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -104,8 +104,8 @@ pub enum EnableOwnershipError {
Command(#[source] std::io::Error),
}
impl Into<ActionErrorKind> for EnableOwnershipError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<EnableOwnershipError> for ActionErrorKind {
fn from(val: EnableOwnershipError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -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<ActionErrorKind> for EncryptApfsVolumeError {
fn into(self) -> ActionErrorKind {
ActionErrorKind::Custom(Box::new(self))
impl From<EncryptApfsVolumeError> for ActionErrorKind {
fn from(val: EncryptApfsVolumeError) -> Self {
ActionErrorKind::Custom(Box::new(val))
}
}

View file

@ -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

View file

@ -55,12 +55,12 @@ async fn get_uuid_for_label(apfs_volume_label: &str) -> Result<Option<Uuid>, 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()),

View file

@ -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<ActionDescription> {
vec![ActionDescription::new(
format!("Remove time machine exclusions"),
"Remove time machine exclusions".to_string(),
vec![],
)]
}

View file

@ -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()
};

View file

@ -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::<Vec<_>>()
.join(", ")
);
)
}
}

View file

@ -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<ActionDescription> {
if self.state == ActionState::Uncompleted {
return vec![];
}
return self.action.revert_description();
self.action.revert_description()
}
/// Perform any execution steps
///

View file

@ -139,7 +139,7 @@ impl<'a> Instrumentation {
}
EnvFilter::try_new(&format!(
"{}={}",
env!("CARGO_PKG_NAME").replace("-", "_"),
env!("CARGO_PKG_NAME").replace('-', "_"),
self.log_level()
))?
},

View file

@ -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() {

View file

@ -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.\

View file

@ -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()
}
}

View file

@ -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::<Vec<_>>(),
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::<Vec<_>>()
.join(", ")
);
)
}
}

View file

@ -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)
}
}

View file

@ -156,9 +156,9 @@ impl Planner for Linux {
}
}
impl Into<BuiltinPlanner> for Linux {
fn into(self) -> BuiltinPlanner {
BuiltinPlanner::Linux(self)
impl From<Linux> for BuiltinPlanner {
fn from(val: Linux) -> Self {
BuiltinPlanner::Linux(val)
}
}
@ -196,11 +196,12 @@ pub(crate) async fn detect_selinux() -> Result<bool, PlannerError> {
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);
}

View file

@ -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()
}
}

View file

@ -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<BuiltinPlanner> for SteamDeck {
fn into(self) -> BuiltinPlanner {
BuiltinPlanner::SteamDeck(self)
impl From<SteamDeck> for BuiltinPlanner {
fn from(val: SteamDeck) -> Self {
BuiltinPlanner::SteamDeck(val)
}
}
@ -445,8 +443,7 @@ pub(crate) async fn detect_requires_bind_mount() -> Result<bool, PlannerError> {
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") => {

View file

@ -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::<Vec<_>>()
.join(", ")
);
)
}
}

View file

@ -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()
}
}