Skip to content

Commit

Permalink
Merge pull request containers#669 from HuijingHei/esp_temp
Browse files Browse the repository at this point in the history
efi: update the ESP by creating a tmpdir and RENAME_EXCHANGE
  • Loading branch information
cgwalters authored Aug 21, 2024
2 parents 70454b2 + e08bc29 commit e65a074
Show file tree
Hide file tree
Showing 9 changed files with 306 additions and 38 deletions.
19 changes: 19 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ path = "src/main.rs"
anyhow = "1.0"
bincode = "1.3.2"
cap-std-ext = "4.0.0"
camino = "1.1.7"
chrono = { version = "0.4.38", features = ["serde"] }
clap = { version = "4.5", default-features = false, features = ["cargo", "derive", "std", "help", "usage", "suggestions"] }
env_logger = "0.11"
fail = { version = "0.5", features = ["failpoints"] }
fn-error-context = "0.2.1"
fs2 = "0.4.3"
hex = "0.4.3"
Expand Down
15 changes: 15 additions & 0 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -396,6 +396,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
}

pub(crate) fn client_run_update() -> Result<()> {
crate::try_fail_point!("update");
let status: Status = status()?;
if status.components.is_empty() && status.adoptable.is_empty() {
println!("No components installed.");
Expand Down Expand Up @@ -489,3 +490,17 @@ pub(crate) fn client_run_validate() -> Result<()> {
}
Ok(())
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_failpoint_update() {
let guard = fail::FailScenario::setup();
fail::cfg("update", "return").unwrap();
let r = client_run_update();
assert_eq!(r.is_err(), true);
guard.teardown();
}
}
2 changes: 1 addition & 1 deletion src/efi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ impl Efi {
log::debug!("Not booted via EFI, skipping firmware update");
return Ok(());
}
let sysroot = Dir::open_ambient_dir(&Path::new("/"), cap_std::ambient_authority())?;
let sysroot = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
let product_name = get_product_name(&sysroot)?;
log::debug!("Get product name: {product_name}");
assert!(product_name.len() > 0);
Expand Down
21 changes: 21 additions & 0 deletions src/failpoints.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
//! Wrappers and utilities on top of the `fail` crate.
// SPDX-License-Identifier: Apache-2.0 OR MIT

/// TODO: Use https://github.com/tikv/fail-rs/pull/68 once it merges
/// copy from https://github.com/coreos/rpm-ostree/commit/aa8d7fb0ceaabfaf10252180e2ddee049d07aae3#diff-adcc419e139605fae34d17b31418dbaf515af2fe9fb766fcbdb2eaad862b3daa
#[macro_export]
macro_rules! try_fail_point {
($name:expr) => {{
if let Some(e) = fail::eval($name, |msg| {
let msg = msg.unwrap_or_else(|| "synthetic failpoint".to_string());
anyhow::Error::msg(msg)
}) {
return Err(From::from(e));
}
}};
($name:expr, $cond:expr) => {{
if $cond {
$crate::try_fail_point!($name);
}
}};
}
Loading

0 comments on commit e65a074

Please sign in to comment.