Skip to content

Commit 140d3ad

Browse files
committed
Add prep_before_update() to remove duplicated lines
`prep_before_update()` is to initialize parent devices to prepare the update
1 parent d5e71a9 commit 140d3ad

File tree

2 files changed

+20
-21
lines changed

2 files changed

+20
-21
lines changed

src/blockdev.rs

+6-7
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,11 @@ pub fn get_esp_partition(device: &str) -> Result<Option<String>> {
6464
Ok(None)
6565
}
6666

67-
/// Find all ESP partitions on the devices with mountpoint boot
67+
/// Find all ESP partitions on the devices
6868
#[allow(dead_code)]
69-
pub fn find_colocated_esps<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
69+
pub fn find_colocated_esps<P: AsRef<Path>>() -> Result<Vec<String>> {
7070
// first, get the parent device
71-
let devices = get_devices(&target_root).with_context(|| "while looking for colocated ESPs")?;
71+
let devices = get_parent_devices();
7272

7373
// now, look for all ESPs on those devices
7474
let mut esps = Vec::new();
@@ -95,12 +95,11 @@ pub fn get_bios_boot_partition(device: &str) -> Result<Option<String>> {
9595
Ok(None)
9696
}
9797

98-
/// Find all bios_boot partitions on the devices with mountpoint boot
98+
/// Find all bios_boot partitions on the devices
9999
#[allow(dead_code)]
100-
pub fn find_colocated_bios_boot<P: AsRef<Path>>(target_root: P) -> Result<Vec<String>> {
100+
pub fn find_colocated_bios_boot<P: AsRef<Path>>() -> Result<Vec<String>> {
101101
// first, get the parent device
102-
let devices =
103-
get_devices(&target_root).with_context(|| "looking for colocated bios_boot parts")?;
102+
let devices = get_parent_devices();
104103

105104
// now, look for all bios_boot parts on those devices
106105
let mut bios_boots = Vec::new();

src/cli/bootupctl.rs

+14-14
Original file line numberDiff line numberDiff line change
@@ -130,26 +130,14 @@ impl CtlCommand {
130130
/// Runner for `update` verb.
131131
fn run_update() -> Result<()> {
132132
ensure_running_in_systemd()?;
133-
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
134-
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
135-
let dest_root = std::fs::read_link(dest_fd)?;
136-
137-
let devices = crate::blockdev::get_devices(&dest_root)
138-
.with_context(|| "while looking for parent devices")?;
139-
crate::blockdev::init_parent_devices(devices);
133+
let sysroot = prep_before_update()?;
140134
bootupd::client_run_update(&sysroot)
141135
}
142136

143137
/// Runner for `update` verb.
144138
fn run_adopt_and_update() -> Result<()> {
145139
ensure_running_in_systemd()?;
146-
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
147-
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
148-
let dest_root = std::fs::read_link(dest_fd)?;
149-
150-
let devices = crate::blockdev::get_devices(&dest_root)
151-
.with_context(|| "while looking for parent devices")?;
152-
crate::blockdev::init_parent_devices(devices);
140+
let sysroot = prep_before_update()?;
153141
bootupd::client_run_adopt_and_update(&sysroot)
154142
}
155143

@@ -228,3 +216,15 @@ fn run_status_in_container(json_format: bool) -> Result<()> {
228216
}
229217
Ok(())
230218
}
219+
220+
/// Initialize parent devices to prepare the update
221+
fn prep_before_update() -> Result<openat::Dir> {
222+
let sysroot = openat::Dir::open("/").context("Opening root dir")?;
223+
let dest_fd = format!("/proc/self/fd/{}", sysroot.as_raw_fd());
224+
let dest_root = std::fs::read_link(dest_fd)?;
225+
226+
let devices = crate::blockdev::get_devices(&dest_root)
227+
.with_context(|| "while looking for parent devices")?;
228+
crate::blockdev::init_parent_devices(devices);
229+
Ok(sysroot)
230+
}

0 commit comments

Comments
 (0)