Skip to content

Commit e65a074

Browse files
authored
Merge pull request #669 from HuijingHei/esp_temp
efi: update the ESP by creating a tmpdir and RENAME_EXCHANGE
2 parents 70454b2 + e08bc29 commit e65a074

File tree

9 files changed

+306
-38
lines changed

9 files changed

+306
-38
lines changed

Cargo.lock

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,11 @@ path = "src/main.rs"
2222
anyhow = "1.0"
2323
bincode = "1.3.2"
2424
cap-std-ext = "4.0.0"
25+
camino = "1.1.7"
2526
chrono = { version = "0.4.38", features = ["serde"] }
2627
clap = { version = "4.5", default-features = false, features = ["cargo", "derive", "std", "help", "usage", "suggestions"] }
2728
env_logger = "0.11"
29+
fail = { version = "0.5", features = ["failpoints"] }
2830
fn-error-context = "0.2.1"
2931
fs2 = "0.4.3"
3032
hex = "0.4.3"

src/bootupd.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -396,6 +396,7 @@ pub(crate) fn print_status(status: &Status) -> Result<()> {
396396
}
397397

398398
pub(crate) fn client_run_update() -> Result<()> {
399+
crate::try_fail_point!("update");
399400
let status: Status = status()?;
400401
if status.components.is_empty() && status.adoptable.is_empty() {
401402
println!("No components installed.");
@@ -489,3 +490,17 @@ pub(crate) fn client_run_validate() -> Result<()> {
489490
}
490491
Ok(())
491492
}
493+
494+
#[cfg(test)]
495+
mod tests {
496+
use super::*;
497+
498+
#[test]
499+
fn test_failpoint_update() {
500+
let guard = fail::FailScenario::setup();
501+
fail::cfg("update", "return").unwrap();
502+
let r = client_run_update();
503+
assert_eq!(r.is_err(), true);
504+
guard.teardown();
505+
}
506+
}

src/efi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ impl Efi {
141141
log::debug!("Not booted via EFI, skipping firmware update");
142142
return Ok(());
143143
}
144-
let sysroot = Dir::open_ambient_dir(&Path::new("/"), cap_std::ambient_authority())?;
144+
let sysroot = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
145145
let product_name = get_product_name(&sysroot)?;
146146
log::debug!("Get product name: {product_name}");
147147
assert!(product_name.len() > 0);

src/failpoints.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Wrappers and utilities on top of the `fail` crate.
2+
// SPDX-License-Identifier: Apache-2.0 OR MIT
3+
4+
/// TODO: Use https://github.com/tikv/fail-rs/pull/68 once it merges
5+
/// copy from https://github.com/coreos/rpm-ostree/commit/aa8d7fb0ceaabfaf10252180e2ddee049d07aae3#diff-adcc419e139605fae34d17b31418dbaf515af2fe9fb766fcbdb2eaad862b3daa
6+
#[macro_export]
7+
macro_rules! try_fail_point {
8+
($name:expr) => {{
9+
if let Some(e) = fail::eval($name, |msg| {
10+
let msg = msg.unwrap_or_else(|| "synthetic failpoint".to_string());
11+
anyhow::Error::msg(msg)
12+
}) {
13+
return Err(From::from(e));
14+
}
15+
}};
16+
($name:expr, $cond:expr) => {{
17+
if $cond {
18+
$crate::try_fail_point!($name);
19+
}
20+
}};
21+
}

0 commit comments

Comments
 (0)