diff --git a/lib/src/install.rs b/lib/src/install.rs index 2834ae44f..5929e4cdd 100644 --- a/lib/src/install.rs +++ b/lib/src/install.rs @@ -662,7 +662,7 @@ async fn initialize_ostree_root(state: &State, root_setup: &RootSetup) -> Result .init_osname(stateroot, cancellable) .context("initializing stateroot")?; - let sysroot_dir = Dir::reopen_dir(&crate::utils::sysroot_fd(&sysroot))?; + let sysroot_dir = crate::utils::sysroot_dir(&sysroot)?; state.tempdir.create_dir("temp-run")?; let temp_run = state.tempdir.open_dir("temp-run")?; diff --git a/lib/src/install/completion.rs b/lib/src/install/completion.rs index e37d2865a..859835588 100644 --- a/lib/src/install/completion.rs +++ b/lib/src/install/completion.rs @@ -276,7 +276,7 @@ pub(crate) async fn impl_completion( let deployment = &sysroot .merge_deployment(stateroot) .ok_or_else(|| anyhow::anyhow!("Failed to find deployment (stateroot={stateroot:?}"))?; - let sysroot_dir = Dir::reopen_dir(&crate::utils::sysroot_fd(&sysroot))?; + let sysroot_dir = crate::utils::sysroot_dir(&sysroot)?; // Create a subdir in /run let rundir = "run/bootc-install"; diff --git a/lib/src/store/mod.rs b/lib/src/store/mod.rs index 56e142e8b..92ab8b54e 100644 --- a/lib/src/store/mod.rs +++ b/lib/src/store/mod.rs @@ -78,7 +78,7 @@ impl Storage { if let Some(imgstore) = self.imgstore.get() { return Ok(imgstore); } - let sysroot_dir = Dir::reopen_dir(&crate::utils::sysroot_fd(&self.sysroot))?; + let sysroot_dir = crate::utils::sysroot_dir(&self.sysroot)?; let imgstore = crate::imgstorage::Storage::create(&sysroot_dir, &self.run)?; Ok(self.imgstore.get_or_init(|| imgstore)) } diff --git a/lib/src/utils.rs b/lib/src/utils.rs index 525b1e70e..b809f016f 100644 --- a/lib/src/utils.rs +++ b/lib/src/utils.rs @@ -40,6 +40,11 @@ pub(crate) fn sysroot_fd(sysroot: &ostree::Sysroot) -> BorrowedFd { unsafe { BorrowedFd::borrow_raw(sysroot.fd()) } } +// Return a cap-std `Dir` type for a sysroot +pub(crate) fn sysroot_dir(sysroot: &ostree::Sysroot) -> Result { + Dir::reopen_dir(&sysroot_fd(sysroot)).map_err(Into::into) +} + // Return a cap-std `Dir` type for a deployment. // TODO: in the future this should perhaps actually mount via composefs pub(crate) fn deployment_fd(