Skip to content

Commit 4b1b90e

Browse files
efi: Do not unmount if mountpoint was already mounted
Signed-off-by: Pragyan Poudyal <pragyanpoudyal41999@gmail.com>
1 parent 9c406ec commit 4b1b90e

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

src/efi.rs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,12 @@ pub(crate) fn is_efi_booted() -> Result<bool> {
8787
.map_err(Into::into)
8888
}
8989

90-
#[derive(Default)]
90+
#[derive(Default, Debug)]
9191
pub(crate) struct Efi {
9292
mountpoint: RefCell<Option<PathBuf>>,
93+
/// Whether the above mountpoint was already mounted or not
94+
/// Won't unmount if it was already mounted
95+
was_mounted: RefCell<bool>,
9396
}
9497

9598
impl Efi {
@@ -116,6 +119,7 @@ impl Efi {
116119
continue;
117120
}
118121
util::ensure_writable_mount(&path)?;
122+
*self.was_mounted.borrow_mut() = true;
119123
found_mount = Some(path);
120124
break;
121125
}
@@ -148,6 +152,7 @@ impl Efi {
148152
if is_mount_point(&mnt)? {
149153
log::debug!("ESP already mounted at {mnt:?}, reusing");
150154
mountpoint = Some(mnt);
155+
*self.was_mounted.borrow_mut() = true;
151156
break;
152157
}
153158
}
@@ -704,7 +709,12 @@ impl Component for Efi {
704709

705710
impl Drop for Efi {
706711
fn drop(&mut self) {
707-
log::debug!("Unmounting");
712+
if *self.was_mounted.borrow() {
713+
log::debug!("mountpoint was already mounted. Won't unmount",);
714+
return;
715+
}
716+
717+
log::debug!("Unmounting {:?}", self.mountpoint);
708718
let _ = self.unmount();
709719
}
710720
}

0 commit comments

Comments
 (0)