From 0b5b22a7658abfefc0a54752a690ab243a0dc556 Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Wed, 18 Nov 2020 18:46:01 +0000 Subject: [PATCH] Thread sysroot through install flow More incremental work on https://github.com/coreos/bootupd/issues/108 --- src/bootupd.rs | 3 ++- src/component.rs | 2 +- src/efi.rs | 17 +++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/bootupd.rs b/src/bootupd.rs index fd749155..10432f09 100644 --- a/src/bootupd.rs +++ b/src/bootupd.rs @@ -23,6 +23,7 @@ pub(crate) enum ClientRequest { } pub(crate) fn install(source_root: &str, dest_root: &str) -> Result<()> { + let source_root = openat::Dir::open(source_root)?; SavedState::ensure_not_present(dest_root) .context("failed to install, invalid re-install attempted")?; @@ -35,7 +36,7 @@ pub(crate) fn install(source_root: &str, dest_root: &str) -> Result<()> { let mut state = SavedState::default(); for component in components.values() { let meta = component - .install(source_root, dest_root) + .install(&source_root, dest_root) .with_context(|| format!("installing component {}", component.name()))?; state.installed.insert(component.name().into(), meta); } diff --git a/src/component.rs b/src/component.rs index 1e9c1f0e..87ea0d5e 100644 --- a/src/component.rs +++ b/src/component.rs @@ -43,7 +43,7 @@ pub(crate) trait Component { /// of a filesystem root, the component should query the mount point to /// determine the block device. /// This will be run during a disk image build process. - fn install(&self, src_root: &str, dest_root: &str) -> Result; + fn install(&self, src_root: &openat::Dir, dest_root: &str) -> Result; /// Implementation of `bootupd generate-update-metadata` for a given component. /// This expects to be run during an "image update build" process. For CoreOS diff --git a/src/efi.rs b/src/efi.rs index 76be8f44..77aabb05 100644 --- a/src/efi.rs +++ b/src/efi.rs @@ -6,6 +6,7 @@ use std::collections::{BTreeMap, BTreeSet}; use std::io::prelude::*; +use std::os::unix::io::AsRawFd; use std::path::{Path, PathBuf}; use std::process::Command; @@ -102,27 +103,27 @@ impl Component for EFI { }) } - fn install(&self, src_root: &str, dest_root: &str) -> Result { - let src_rootd = openat::Dir::open(src_root)?; - let meta = if let Some(meta) = get_component_update(&src_rootd, self)? { + fn install(&self, src_root: &openat::Dir, dest_root: &str) -> Result { + let meta = if let Some(meta) = get_component_update(&src_root, self)? { meta } else { anyhow::bail!("No update metadata for component {} found", self.name()); }; - let srcdir = component_updatedir(src_root, self); - let srcd = openat::Dir::open(&srcdir) - .with_context(|| format!("opening src dir {}", srcdir.display()))?; - let ft = crate::filetree::FileTree::new_from_dir(&srcd)?; + let srcdir_name = component_updatedirname(self); + let ft = crate::filetree::FileTree::new_from_dir(&src_root.sub_dir(&srcdir_name)?)?; let destdir = Path::new(dest_root).join(MOUNT_PATH); { let destd = openat::Dir::open(&destdir) .with_context(|| format!("opening dest dir {}", destdir.display()))?; validate_esp(&destd)?; } + // TODO - add some sort of API that allows directly setting the working + // directory to a file descriptor. let r = std::process::Command::new("cp") .args(&["-rp", "--reflink=auto"]) - .arg(&srcdir) + .arg(&srcdir_name) .arg(&destdir) + .current_dir(format!("/proc/self/fd/{}", src_root.as_raw_fd())) .status()?; if !r.success() { anyhow::bail!("Failed to copy");