diff options
author | Thomas Mühlbacher <tmuehlbacher@posteo.net> | 2024-06-26 18:14:24 +0200 |
---|---|---|
committer | Thomas Mühlbacher <tmuehlbacher@posteo.net> | 2024-06-26 19:14:45 +0200 |
commit | 795585e2899f9f785b284339cd7b0097747998c4 (patch) | |
tree | 5cbc7dd246dd478b223ab48f67e403791576434e /src/commands | |
parent | 9bd3ada1d15d7533ff02fd5cdcbab53ecace7906 (diff) |
refactor: simplify branches for parsing dev
Less repetition and no nested if/else.
Signed-off-by: Thomas Mühlbacher <tmuehlbacher@posteo.net>
Diffstat (limited to 'src/commands')
-rw-r--r-- | src/commands/mount.rs | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/src/commands/mount.rs b/src/commands/mount.rs index 7a994bde..18b4aae5 100644 --- a/src/commands/mount.rs +++ b/src/commands/mount.rs @@ -317,26 +317,24 @@ fn cmd_mount_inner(cli: &Cli) -> Result<()> { // Grab the udev information once let udev_info = udev_bcachefs_info()?; - let (devices, sbs) = if let Some(uuid) = cli.dev.strip_prefix("UUID=") { - devs_str_sbs_from_uuid(&udev_info, uuid)? - } else if let Some(uuid) = cli.dev.strip_prefix("OLD_BLKID_UUID=") { + let (devices, sbs) = if let Some(("UUID" | "OLD_BLKID_UUID", uuid)) = cli.dev.split_once('=') { devs_str_sbs_from_uuid(&udev_info, uuid)? + } else if cli.dev.contains(':') { + // If the device string contains ":" we will assume the user knows the + // entire list. If they supply a single device it could be either the FS + // only has 1 device or it's 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. + + let sbs = cli + .dev + .split(':') + .map(read_super_silent) + .collect::<Result<Vec<_>>>()?; + + (cli.dev.clone(), sbs) } else { - // If the device string contains ":" we will assume the user knows the entire list. - // If they supply a single device it could be either the FS only has 1 device or it's - // 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. - if cli.dev.contains(':') { - let sbs = cli - .dev - .split(':') - .map(read_super_silent) - .collect::<Result<Vec<_>>>()?; - - (cli.dev.clone(), sbs) - } else { - devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))? - } + devs_str_sbs_from_device(&udev_info, Path::new(&cli.dev))? }; ensure!(!sbs.is_empty(), "No device(s) to mount specified"); |