tree-wide: rust: run cargo fmt

The 2024 style guide changed some things, which causes quite some churn. Most of
boils down to the changed import order, now choosing types before function
items - which is the other way round then before.

No functional changes.

Signed-off-by: Christoph Heiss <c.heiss@proxmox.com>
This commit is contained in:
Christoph Heiss 2025-02-28 10:27:33 +01:00 committed by Thomas Lamprecht
parent c305be5e91
commit a1575df428
24 changed files with 71 additions and 64 deletions

View File

@ -1,4 +1,4 @@
use anyhow::{bail, format_err, Result}; use anyhow::{Result, bail, format_err};
use clap::{Args, Parser, Subcommand, ValueEnum}; use clap::{Args, Parser, Subcommand, ValueEnum};
use glob::Pattern; use glob::Pattern;
use serde::Serialize; use serde::Serialize;
@ -14,9 +14,9 @@ use proxmox_auto_installer::{
answer::{Answer, FilterMatch}, answer::{Answer, FilterMatch},
sysinfo::SysInfo, sysinfo::SysInfo,
utils::{ utils::{
get_matched_udev_indexes, get_nic_list, get_single_udev_index, AutoInstSettings, FetchAnswerFrom, HttpOptions, get_matched_udev_indexes, get_nic_list,
verify_email_and_root_password_settings, verify_first_boot_settings, get_single_udev_index, verify_email_and_root_password_settings, verify_first_boot_settings,
verify_locale_settings, AutoInstSettings, FetchAnswerFrom, HttpOptions, verify_locale_settings,
}, },
}; };
use proxmox_installer_common::{FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME}; use proxmox_installer_common::{FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME};
@ -624,7 +624,9 @@ fn check_prepare_requirements(args: &CommandPrepareISO) -> Result<()> {
{ {
Ok(v) => { Ok(v) => {
if !v.success() { if !v.success() {
bail!("The source ISO file is not able to be installed automatically. Please try a more current one."); bail!(
"The source ISO file is not able to be installed automatically. Please try a more current one."
);
} }
} }
Err(err) if err.kind() == io::ErrorKind::NotFound => { Err(err) if err.kind() == io::ErrorKind::NotFound => {

View File

@ -1,4 +1,4 @@
use anyhow::{format_err, Result}; use anyhow::{Result, format_err};
use clap::ValueEnum; use clap::ValueEnum;
use proxmox_installer_common::{ use proxmox_installer_common::{
options::{ options::{
@ -280,7 +280,7 @@ impl TryFrom<DiskSetup> for Disks {
} }
match source.zfs { match source.zfs {
None | Some(ZfsOptions { raid: None, .. }) => { None | Some(ZfsOptions { raid: None, .. }) => {
return Err("ZFS raid level 'zfs.raid' must be set") return Err("ZFS raid level 'zfs.raid' must be set");
} }
Some(opts) => (FsType::Zfs(opts.raid.unwrap()), FsOptions::ZFS(opts)), Some(opts) => (FsType::Zfs(opts.raid.unwrap()), FsOptions::ZFS(opts)),
} }
@ -291,7 +291,7 @@ impl TryFrom<DiskSetup> for Disks {
} }
match source.btrfs { match source.btrfs {
None | Some(BtrfsOptions { raid: None, .. }) => { None | Some(BtrfsOptions { raid: None, .. }) => {
return Err("BTRFS raid level 'btrfs.raid' must be set") return Err("BTRFS raid level 'btrfs.raid' must be set");
} }
Some(opts) => (FsType::Btrfs(opts.raid.unwrap()), FsOptions::BTRFS(opts)), Some(opts) => (FsType::Btrfs(opts.raid.unwrap()), FsOptions::BTRFS(opts)),
} }

View File

@ -1,5 +1,5 @@
use anyhow::{bail, format_err, Result}; use anyhow::{Result, bail, format_err};
use log::{error, info, LevelFilter}; use log::{LevelFilter, error, info};
use std::{ use std::{
env, env,
fs::{self, File}, fs::{self, File},
@ -9,12 +9,11 @@ use std::{
}; };
use proxmox_installer_common::{ use proxmox_installer_common::{
http, FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME, RUNTIME_DIR, http,
setup::{ setup::{
installer_setup, read_json, spawn_low_level_installer, LocaleInfo, LowLevelMessage, LocaleInfo, LowLevelMessage, RuntimeInfo, SetupInfo, installer_setup, read_json,
RuntimeInfo, SetupInfo, spawn_low_level_installer,
}, },
FIRST_BOOT_EXEC_MAX_SIZE, FIRST_BOOT_EXEC_NAME, RUNTIME_DIR,
}; };
use proxmox_auto_installer::{ use proxmox_auto_installer::{

View File

@ -1,4 +1,4 @@
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use log::{Level, Metadata, Record}; use log::{Level, Metadata, Record};
use std::{fs::File, io::Write, sync::Mutex, sync::OnceLock}; use std::{fs::File, io::Write, sync::Mutex, sync::OnceLock};

View File

@ -1,8 +1,8 @@
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use proxmox_installer_common::{ use proxmox_installer_common::{
RUNTIME_DIR,
setup::{IsoInfo, ProductConfig, SetupInfo}, setup::{IsoInfo, ProductConfig, SetupInfo},
sysinfo::SystemDMI, sysinfo::SystemDMI,
RUNTIME_DIR,
}; };
use serde::Serialize; use serde::Serialize;
use std::{fs, io, path::PathBuf}; use std::{fs, io, path::PathBuf};

View File

@ -1,4 +1,4 @@
use anyhow::{bail, Context, Result}; use anyhow::{Context, Result, bail};
use clap::ValueEnum; use clap::ValueEnum;
use glob::Pattern; use glob::Pattern;
use log::info; use log::info;
@ -9,12 +9,12 @@ use crate::{
udevinfo::UdevInfo, udevinfo::UdevInfo,
}; };
use proxmox_installer_common::{ use proxmox_installer_common::{
options::{email_validate, FsType, NetworkOptions, ZfsChecksumOption, ZfsCompressOption}, ROOT_PASSWORD_MIN_LENGTH,
options::{FsType, NetworkOptions, ZfsChecksumOption, ZfsCompressOption, email_validate},
setup::{ setup::{
InstallBtrfsOption, InstallConfig, InstallFirstBootSetup, InstallRootPassword, InstallBtrfsOption, InstallConfig, InstallFirstBootSetup, InstallRootPassword,
InstallZfsOption, LocaleInfo, RuntimeInfo, SetupInfo, InstallZfsOption, LocaleInfo, RuntimeInfo, SetupInfo,
}, },
ROOT_PASSWORD_MIN_LENGTH,
}; };
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
@ -286,7 +286,9 @@ fn verify_filesystem_settings(answer: &Answer, setup_info: &SetupInfo) -> Result
info!("Verifying filesystem settings"); info!("Verifying filesystem settings");
if answer.disks.fs_type.is_btrfs() && !setup_info.config.enable_btrfs { if answer.disks.fs_type.is_btrfs() && !setup_info.config.enable_btrfs {
bail!("BTRFS is not supported as a root filesystem for the product or the release of this ISO."); bail!(
"BTRFS is not supported as a root filesystem for the product or the release of this ISO."
);
} }
Ok(()) Ok(())
@ -339,13 +341,17 @@ pub fn verify_email_and_root_password_settings(answer: &Answer) -> Result<()> {
&answer.global.root_password_hashed, &answer.global.root_password_hashed,
) { ) {
(Some(_), Some(_)) => { (Some(_), Some(_)) => {
bail!("`global.root_password` and `global.root_password_hashed` cannot be set at the same time"); bail!(
"`global.root_password` and `global.root_password_hashed` cannot be set at the same time"
);
} }
(None, None) => { (None, None) => {
bail!("One of `global.root_password` or `global.root_password_hashed` must be set"); bail!("One of `global.root_password` or `global.root_password_hashed` must be set");
} }
(Some(password), None) if password.len() < ROOT_PASSWORD_MIN_LENGTH => { (Some(password), None) if password.len() < ROOT_PASSWORD_MIN_LENGTH => {
bail!("`global.root_password` must be at least {ROOT_PASSWORD_MIN_LENGTH} characters long"); bail!(
"`global.root_password` must be at least {ROOT_PASSWORD_MIN_LENGTH} characters long"
);
} }
_ => Ok(()), _ => Ok(()),
} }

View File

@ -8,7 +8,7 @@ use proxmox_auto_installer::udevinfo::UdevInfo;
use proxmox_auto_installer::utils::parse_answer; use proxmox_auto_installer::utils::parse_answer;
use proxmox_installer_common::setup::{ use proxmox_installer_common::setup::{
load_installer_setup_files, read_json, LocaleInfo, RuntimeInfo, SetupInfo, LocaleInfo, RuntimeInfo, SetupInfo, load_installer_setup_files, read_json,
}; };
fn get_test_resource_path() -> Result<PathBuf, String> { fn get_test_resource_path() -> Result<PathBuf, String> {

View File

@ -4,13 +4,13 @@ use std::{
process::Command, process::Command,
}; };
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use clap::{Args, Parser, Subcommand, ValueEnum}; use clap::{Args, Parser, Subcommand, ValueEnum};
use nix::mount::{mount, umount, MsFlags}; use nix::mount::{MsFlags, mount, umount};
use proxmox_installer_common::{ use proxmox_installer_common::{
RUNTIME_DIR,
options::FsType, options::FsType,
setup::{InstallConfig, SetupInfo}, setup::{InstallConfig, SetupInfo},
RUNTIME_DIR,
}; };
use regex::Regex; use regex::Regex;
@ -132,7 +132,9 @@ fn get_fs(filesystem: Option<Filesystems>) -> Result<Filesystems> {
None => { None => {
let low_level_config = match get_low_level_config() { let low_level_config = match get_low_level_config() {
Ok(c) => c, Ok(c) => c,
Err(_) => bail!("Could not fetch config from previous installation. Please specify file system with -f."), Err(_) => bail!(
"Could not fetch config from previous installation. Please specify file system with -f."
),
}; };
Filesystems::from(low_level_config.filesys) Filesystems::from(low_level_config.filesys)
} }
@ -292,7 +294,9 @@ fn get_btrfs_uuid() -> Result<String> {
let uuid_list = uuids let uuid_list = uuids
.iter() .iter()
.fold(String::new(), |acc, &arg| format!("{acc}\n{arg}")); .fold(String::new(), |acc, &arg| format!("{acc}\n{arg}"));
bail!("Found {i} UUIDs:{uuid_list}\nPlease specify the UUID to use with the --btrfs-uuid parameter") bail!(
"Found {i} UUIDs:{uuid_list}\nPlease specify the UUID to use with the --btrfs-uuid parameter"
)
} }
_ => (), _ => (),
} }

View File

@ -1,4 +1,4 @@
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use log::info; use log::info;
use serde::Serialize; use serde::Serialize;
use std::{ use std::{

View File

@ -1,4 +1,4 @@
use anyhow::{bail, format_err, Result}; use anyhow::{Result, bail, format_err};
use log::{info, warn}; use log::{info, warn};
use std::{ use std::{
fs::{self, create_dir_all}, fs::{self, create_dir_all},

View File

@ -1,8 +1,8 @@
use std::process::ExitCode; use std::process::ExitCode;
use std::{fs, path::PathBuf}; use std::{fs, path::PathBuf};
use anyhow::{bail, format_err, Result}; use anyhow::{Result, bail, format_err};
use log::{error, info, LevelFilter}; use log::{LevelFilter, error, info};
use proxmox_auto_installer::{ use proxmox_auto_installer::{
log::AutoInstLogger, log::AutoInstLogger,

View File

@ -1,4 +1,4 @@
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use regex::Regex; use regex::Regex;
use serde::{Deserialize, Serialize}; use serde::{Deserialize, Serialize};
use std::net::{IpAddr, Ipv4Addr}; use std::net::{IpAddr, Ipv4Addr};

View File

@ -9,7 +9,7 @@ use std::{
process::{self, Command, Stdio}, process::{self, Command, Stdio},
}; };
use serde::{de, Deserialize, Deserializer, Serialize, Serializer}; use serde::{Deserialize, Deserializer, Serialize, Serializer, de};
use crate::{ use crate::{
options::{ options::{

View File

@ -1,6 +1,6 @@
use std::{collections::HashMap, fs}; use std::{collections::HashMap, fs};
use anyhow::{bail, Result}; use anyhow::{Result, bail};
use serde::Serialize; use serde::Serialize;
const DMI_PATH: &str = "/sys/devices/virtual/dmi/id"; const DMI_PATH: &str = "/sys/devices/virtual/dmi/id";

View File

@ -117,11 +117,7 @@ impl<'de> Deserialize<'de> for CidrAddress {
serde_plain::derive_serialize_from_display!(CidrAddress); serde_plain::derive_serialize_from_display!(CidrAddress);
fn mask_limit(addr: &IpAddr) -> usize { fn mask_limit(addr: &IpAddr) -> usize {
if addr.is_ipv4() { if addr.is_ipv4() { 32 } else { 128 }
32
} else {
128
}
} }
/// Possible errors that might occur when parsing FQDNs. /// Possible errors that might occur when parsing FQDNs.

View File

@ -19,7 +19,7 @@ use std::{
process::{Command, ExitCode}, process::{Command, ExitCode},
}; };
use anyhow::{anyhow, bail, Context, Result}; use anyhow::{Context, Result, anyhow, bail};
use proxmox_auto_installer::{ use proxmox_auto_installer::{
answer::{Answer, PostNotificationHookInfo}, answer::{Answer, PostNotificationHookInfo},
udevinfo::{UdevInfo, UdevProperties}, udevinfo::{UdevInfo, UdevProperties},
@ -27,8 +27,8 @@ use proxmox_auto_installer::{
use proxmox_installer_common::{ use proxmox_installer_common::{
options::{Disk, FsType}, options::{Disk, FsType},
setup::{ setup::{
load_installer_setup_files, BootType, InstallConfig, IsoInfo, ProxmoxProduct, RuntimeInfo, BootType, InstallConfig, IsoInfo, ProxmoxProduct, RuntimeInfo, SetupInfo,
SetupInfo, load_installer_setup_files,
}, },
sysinfo::SystemDMI, sysinfo::SystemDMI,
utils::CidrAddress, utils::CidrAddress,

View File

@ -3,6 +3,7 @@
use std::{collections::HashMap, env, net::IpAddr}; use std::{collections::HashMap, env, net::IpAddr};
use cursive::{ use cursive::{
Cursive, CursiveRunnable, ScreenId, View, XY,
event::Event, event::Event,
theme::{ColorStyle, Effect, Effects, PaletteColor, Style}, theme::{ColorStyle, Effect, Effects, PaletteColor, Style},
view::{Nameable, Offset, Resizable, ViewWrapper}, view::{Nameable, Offset, Resizable, ViewWrapper},
@ -10,17 +11,16 @@ use cursive::{
Button, Checkbox, Dialog, DummyView, EditView, Layer, LinearLayout, PaddedView, Panel, Button, Checkbox, Dialog, DummyView, EditView, Layer, LinearLayout, PaddedView, Panel,
ResizedView, ScrollView, SelectView, StackView, TextView, ResizedView, ScrollView, SelectView, StackView, TextView,
}, },
Cursive, CursiveRunnable, ScreenId, View, XY,
}; };
mod options; mod options;
use options::{InstallerOptions, PasswordOptions}; use options::{InstallerOptions, PasswordOptions};
use proxmox_installer_common::{ use proxmox_installer_common::{
options::{email_validate, BootdiskOptions, NetworkOptions, TimezoneOptions},
setup::{installer_setup, LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo},
utils::Fqdn,
ROOT_PASSWORD_MIN_LENGTH, ROOT_PASSWORD_MIN_LENGTH,
options::{BootdiskOptions, NetworkOptions, TimezoneOptions, email_validate},
setup::{LocaleInfo, ProxmoxProduct, RuntimeInfo, SetupInfo, installer_setup},
utils::Fqdn,
}; };
mod setup; mod setup;

View File

@ -1,11 +1,11 @@
use crate::SummaryOption; use crate::SummaryOption;
use proxmox_installer_common::{ use proxmox_installer_common::{
EMAIL_DEFAULT_PLACEHOLDER,
options::{ options::{
BootdiskOptions, BtrfsRaidLevel, FsType, NetworkOptions, TimezoneOptions, ZfsRaidLevel, BootdiskOptions, BtrfsRaidLevel, FsType, NetworkOptions, TimezoneOptions, ZfsRaidLevel,
}, },
setup::LocaleInfo, setup::LocaleInfo,
EMAIL_DEFAULT_PLACEHOLDER,
}; };
pub const FS_TYPES: &[FsType] = { pub const FS_TYPES: &[FsType] = {
@ -103,7 +103,7 @@ mod tests {
state: InterfaceState::Up, state: InterfaceState::Up,
mac: "01:23:45:67:89:ab".to_owned(), mac: "01:23:45:67:89:ab".to_owned(),
addresses: Some(vec![ addresses: Some(vec![
CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap() CidrAddress::new(Ipv4Addr::new(192, 168, 0, 2), 24).unwrap(),
]), ]),
}, },
); );

View File

@ -4,17 +4,17 @@ use std::{
}; };
use cursive::{ use cursive::{
Cursive, Vec2, View,
view::{Nameable, Resizable, ViewWrapper}, view::{Nameable, Resizable, ViewWrapper},
views::{ views::{
Button, Dialog, DummyView, LinearLayout, NamedView, PaddedView, Panel, ScrollView, Button, Dialog, DummyView, LinearLayout, NamedView, PaddedView, Panel, ScrollView,
SelectView, TextView, ViewRef, SelectView, TextView, ViewRef,
}, },
Cursive, Vec2, View,
}; };
use super::{DiskSizeEditView, FormView, IntegerEditView, TabbedView}; use super::{DiskSizeEditView, FormView, IntegerEditView, TabbedView};
use crate::options::FS_TYPES;
use crate::InstallerState; use crate::InstallerState;
use crate::options::FS_TYPES;
use proxmox_installer_common::{ use proxmox_installer_common::{
disk_checks::{ disk_checks::{
@ -22,9 +22,9 @@ use proxmox_installer_common::{
check_zfs_raid_config, check_zfs_raid_config,
}, },
options::{ options::{
AdvancedBootdiskOptions, BootdiskOptions, BtrfsBootdiskOptions, Disk, FsType, AdvancedBootdiskOptions, BTRFS_COMPRESS_OPTIONS, BootdiskOptions, BtrfsBootdiskOptions,
LvmBootdiskOptions, ZfsBootdiskOptions, BTRFS_COMPRESS_OPTIONS, ZFS_CHECKSUM_OPTIONS, Disk, FsType, LvmBootdiskOptions, ZFS_CHECKSUM_OPTIONS, ZFS_COMPRESS_OPTIONS,
ZFS_COMPRESS_OPTIONS, ZfsBootdiskOptions,
}, },
setup::{BootType, ProductConfig, ProxmoxProduct, RuntimeInfo}, setup::{BootType, ProductConfig, ProxmoxProduct, RuntimeInfo},
}; };

View File

@ -1,8 +1,8 @@
use cursive::{ use cursive::{
CbSink, Cursive,
utils::Counter, utils::Counter,
view::{Nameable, Resizable, ViewWrapper}, view::{Nameable, Resizable, ViewWrapper},
views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextView}, views::{Dialog, DummyView, LinearLayout, PaddedView, ProgressBar, TextView},
CbSink, Cursive,
}; };
use std::{ use std::{
fs::File, fs::File,
@ -12,8 +12,8 @@ use std::{
time::Duration, time::Duration,
}; };
use crate::{abort_install_button, prompt_dialog, InstallerState}; use crate::{InstallerState, abort_install_button, prompt_dialog};
use proxmox_installer_common::setup::{spawn_low_level_installer, InstallConfig, LowLevelMessage}; use proxmox_installer_common::setup::{InstallConfig, LowLevelMessage, spawn_low_level_installer};
pub struct InstallProgressView { pub struct InstallProgressView {
view: PaddedView<LinearLayout>, view: PaddedView<LinearLayout>,

View File

@ -1,11 +1,11 @@
use std::{net::IpAddr, str::FromStr, sync::Arc}; use std::{net::IpAddr, str::FromStr, sync::Arc};
use cursive::{ use cursive::{
Printer, Rect, Vec2, View,
event::{Event, EventResult}, event::{Event, EventResult},
theme::BaseColor, theme::BaseColor,
view::{Resizable, ViewWrapper}, view::{Resizable, ViewWrapper},
views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView}, views::{EditView, LinearLayout, NamedView, ResizedView, SelectView, TextView},
Printer, Rect, Vec2, View,
}; };
use proxmox_installer_common::utils::CidrAddress; use proxmox_installer_common::utils::CidrAddress;

View File

@ -1,12 +1,12 @@
use std::borrow::{Borrow, BorrowMut}; use std::borrow::{Borrow, BorrowMut};
use cursive::{ use cursive::{
Printer, Vec2, View,
direction::Direction, direction::Direction,
event::{AnyCb, Event, EventResult, Key}, event::{AnyCb, Event, EventResult, Key},
theme::{ColorStyle, PaletteColor}, theme::{ColorStyle, PaletteColor},
utils::{markup::StyledString, span::SpannedStr}, utils::{markup::StyledString, span::SpannedStr},
view::{CannotFocus, IntoBoxedView, Selector, ViewNotFound}, view::{CannotFocus, IntoBoxedView, Selector, ViewNotFound},
Printer, Vec2, View,
}; };
pub struct TabbedView { pub struct TabbedView {

View File

@ -1,8 +1,8 @@
use cursive::{ use cursive::{
Printer, Rect, Vec2, View,
direction::Direction, direction::Direction,
event::{Event, EventResult}, event::{Event, EventResult},
view::{scroll, CannotFocus}, view::{CannotFocus, scroll},
Printer, Rect, Vec2, View,
}; };
const HEADER_HEIGHT: usize = 2; const HEADER_HEIGHT: usize = 2;

View File

@ -1,11 +1,11 @@
use cursive::{ use cursive::{
Cursive,
view::{Nameable, ViewWrapper}, view::{Nameable, ViewWrapper},
views::{Dialog, NamedView, SelectView}, views::{Dialog, NamedView, SelectView},
Cursive,
}; };
use super::FormView; use super::FormView;
use crate::{system, InstallerState}; use crate::{InstallerState, system};
use proxmox_installer_common::{ use proxmox_installer_common::{
options::TimezoneOptions, options::TimezoneOptions,
setup::{KeyboardMapping, LocaleInfo}, setup::{KeyboardMapping, LocaleInfo},