mirror of
https://github.com/koverstreet/bcachefs-tools.git
synced 2025-02-23 00:00:02 +03:00
refactor: change some fn type sigs and simplify
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
This commit is contained in:
parent
20f7954cdb
commit
0ca3233518
@ -192,8 +192,8 @@ fn get_devices_by_uuid(
|
|||||||
#[allow(clippy::type_complexity)]
|
#[allow(clippy::type_complexity)]
|
||||||
fn get_uuid_for_dev_node(
|
fn get_uuid_for_dev_node(
|
||||||
udev_bcachefs: &HashMap<String, Vec<String>>,
|
udev_bcachefs: &HashMap<String, Vec<String>>,
|
||||||
device: &std::path::PathBuf,
|
device: impl AsRef<Path>,
|
||||||
) -> anyhow::Result<(Option<Uuid>, Option<(PathBuf, bch_sb_handle)>)> {
|
) -> Result<(Option<Uuid>, Option<(PathBuf, bch_sb_handle)>)> {
|
||||||
let canonical = fs::canonicalize(device)?;
|
let canonical = fs::canonicalize(device)?;
|
||||||
|
|
||||||
if !udev_bcachefs.is_empty() {
|
if !udev_bcachefs.is_empty() {
|
||||||
@ -261,11 +261,11 @@ pub struct Cli {
|
|||||||
|
|
||||||
fn devs_str_sbs_from_uuid(
|
fn devs_str_sbs_from_uuid(
|
||||||
udev_info: &HashMap<String, Vec<String>>,
|
udev_info: &HashMap<String, Vec<String>>,
|
||||||
uuid: String,
|
uuid: &str,
|
||||||
) -> anyhow::Result<(String, Vec<bch_sb_handle>)> {
|
) -> anyhow::Result<(String, Vec<bch_sb_handle>)> {
|
||||||
debug!("enumerating devices with UUID {}", uuid);
|
debug!("enumerating devices with UUID {}", uuid);
|
||||||
|
|
||||||
let devs_sbs = Uuid::parse_str(&uuid).map(|uuid| get_devices_by_uuid(udev_info, uuid))??;
|
let devs_sbs = Uuid::parse_str(uuid).map(|uuid| get_devices_by_uuid(udev_info, uuid))??;
|
||||||
|
|
||||||
let devs_str = devs_sbs
|
let devs_str = devs_sbs
|
||||||
.iter()
|
.iter()
|
||||||
@ -280,7 +280,7 @@ fn devs_str_sbs_from_uuid(
|
|||||||
|
|
||||||
fn devs_str_sbs_from_device(
|
fn devs_str_sbs_from_device(
|
||||||
udev_info: &HashMap<String, Vec<String>>,
|
udev_info: &HashMap<String, Vec<String>>,
|
||||||
device: &std::path::PathBuf,
|
device: impl AsRef<Path>,
|
||||||
) -> anyhow::Result<(String, Vec<bch_sb_handle>)> {
|
) -> anyhow::Result<(String, Vec<bch_sb_handle>)> {
|
||||||
let (uuid, sb_info) = get_uuid_for_dev_node(udev_info, device)?;
|
let (uuid, sb_info) = get_uuid_for_dev_node(udev_info, device)?;
|
||||||
|
|
||||||
@ -297,10 +297,10 @@ fn devs_str_sbs_from_device(
|
|||||||
let dev = path.into_os_string().into_string().unwrap();
|
let dev = path.into_os_string().into_string().unwrap();
|
||||||
Ok((dev, vec![sb]))
|
Ok((dev, vec![sb]))
|
||||||
} else {
|
} else {
|
||||||
devs_str_sbs_from_uuid(udev_info, uuid.to_string())
|
devs_str_sbs_from_uuid(udev_info, &uuid.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
(Some(uuid), None) => devs_str_sbs_from_uuid(udev_info, uuid.to_string()),
|
(Some(uuid), None) => devs_str_sbs_from_uuid(udev_info, &uuid.to_string()),
|
||||||
_ => Ok((String::new(), Vec::new())),
|
_ => Ok((String::new(), Vec::new())),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -309,11 +309,9 @@ fn cmd_mount_inner(opt: Cli) -> Result<()> {
|
|||||||
// Grab the udev information once
|
// Grab the udev information once
|
||||||
let udev_info = udev_bcachefs_info()?;
|
let udev_info = udev_bcachefs_info()?;
|
||||||
|
|
||||||
let (devices, sbs) = if opt.dev.starts_with("UUID=") {
|
let (devices, sbs) = if let Some(uuid) = opt.dev.strip_prefix("UUID=") {
|
||||||
let uuid = opt.dev.replacen("UUID=", "", 1);
|
|
||||||
devs_str_sbs_from_uuid(&udev_info, uuid)?
|
devs_str_sbs_from_uuid(&udev_info, uuid)?
|
||||||
} else if opt.dev.starts_with("OLD_BLKID_UUID=") {
|
} else if let Some(uuid) = opt.dev.strip_prefix("OLD_BLKID_UUID=") {
|
||||||
let uuid = opt.dev.replacen("OLD_BLKID_UUID=", "", 1);
|
|
||||||
devs_str_sbs_from_uuid(&udev_info, uuid)?
|
devs_str_sbs_from_uuid(&udev_info, uuid)?
|
||||||
} else {
|
} else {
|
||||||
// If the device string contains ":" we will assume the user knows the entire list.
|
// If the device string contains ":" we will assume the user knows the entire list.
|
||||||
@ -321,16 +319,15 @@ fn cmd_mount_inner(opt: Cli) -> Result<()> {
|
|||||||
// only 1 of a number of devices which are part of the FS. This appears to be the case
|
// only 1 of a number of devices which are part of the FS. This appears to be the case
|
||||||
// when we get called during fstab mount processing and the fstab specifies a UUID.
|
// when we get called during fstab mount processing and the fstab specifies a UUID.
|
||||||
if opt.dev.contains(':') {
|
if opt.dev.contains(':') {
|
||||||
let mut block_devices_to_mount = Vec::new();
|
let sbs = opt
|
||||||
|
.dev
|
||||||
|
.split(':')
|
||||||
|
.map(read_super_silent)
|
||||||
|
.collect::<Result<Vec<_>>>()?;
|
||||||
|
|
||||||
for dev in opt.dev.split(':') {
|
(opt.dev, sbs)
|
||||||
let dev = PathBuf::from(dev);
|
|
||||||
block_devices_to_mount.push(read_super_silent(&dev)?);
|
|
||||||
}
|
|
||||||
|
|
||||||
(opt.dev, block_devices_to_mount)
|
|
||||||
} else {
|
} else {
|
||||||
devs_str_sbs_from_device(&udev_info, &PathBuf::from(opt.dev))?
|
devs_str_sbs_from_device(&udev_info, Path::new(&opt.dev))?
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user