Skip to content

Commit 691910d

Browse files
committed
blockdev: Fold listing fn
We only have a case for listing one device. Signed-off-by: Colin Walters <[email protected]>
1 parent 1464acb commit 691910d

File tree

1 file changed

+4
-9
lines changed

1 file changed

+4
-9
lines changed

lib/src/blockdev.rs

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,11 @@ pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
9292
)
9393
}
9494

95-
fn list_impl(dev: Option<&Utf8Path>) -> Result<Vec<Device>> {
95+
#[context("Listing device {dev}")]
96+
pub(crate) fn list_dev(dev: &Utf8Path) -> Result<Device> {
9697
let o = Command::new("lsblk")
9798
.args(["-J", "-b", "-O"])
98-
.args(dev)
99+
.arg(dev)
99100
.output()?;
100101
if !o.status.success() {
101102
return Err(anyhow::anyhow!("Failed to list block devices"));
@@ -104,13 +105,7 @@ fn list_impl(dev: Option<&Utf8Path>) -> Result<Vec<Device>> {
104105
for dev in devs.blockdevices.iter_mut() {
105106
dev.backfill_missing()?;
106107
}
107-
Ok(devs.blockdevices)
108-
}
109-
110-
#[context("Listing device {dev}")]
111-
pub(crate) fn list_dev(dev: &Utf8Path) -> Result<Device> {
112-
let devices = list_impl(Some(dev))?;
113-
devices
108+
devs.blockdevices
114109
.into_iter()
115110
.next()
116111
.ok_or_else(|| anyhow!("no device output from lsblk for {dev}"))

0 commit comments

Comments
 (0)