Skip to content

Commit 95fb311

Browse files
authored
Merge pull request #989 from cgwalters/rhsm-atomic
two minor rhsm followups
2 parents c88fcfd + e6223aa commit 95fb311

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

lib/src/rhsm.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Integration with Red Hat Subscription Manager
22
3-
use anyhow::Result;
4-
use cap_std::fs::{Dir, OpenOptions};
5-
use cap_std_ext::cap_std;
3+
use anyhow::{Context, Result};
4+
use cap_std::fs::Dir;
5+
use cap_std_ext::{cap_std, dirext::CapStdExtDirExt};
66
use fn_error_context::context;
77
use serde::Serialize;
88

@@ -96,11 +96,11 @@ pub(crate) async fn publish_facts(root: &Dir) -> Result<()> {
9696
let (_deployments, host) = crate::status::get_status(&sysroot, booted_deployment.as_ref())?;
9797

9898
let facts = RhsmFacts::from(host.status);
99-
let mut bootc_facts_file = root.open_with(
100-
FACTS_PATH,
101-
OpenOptions::new().write(true).create(true).truncate(true),
102-
)?;
103-
serde_json::to_writer_pretty(&mut bootc_facts_file, &facts)?;
99+
root.atomic_replace_with(FACTS_PATH, |w| {
100+
serde_json::to_writer_pretty(w, &facts)?;
101+
anyhow::Ok(())
102+
})
103+
.with_context(|| format!("Writing {FACTS_PATH}"))?;
104104
Ok(())
105105
}
106106

tests/booted/test-image-pushpull-upgrade.nu

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,16 @@ RUN echo test content > /usr/share/blah.txt
4646
# Just sanity check it
4747
let v = podman run --rm localhost/bootc-derived cat /usr/share/blah.txt | str trim
4848
assert equal $v "test content"
49+
50+
let orig_root_mtime = ls -Dl /ostree/bootc | get modified
51+
4952
# Now, fetch it back into the bootc storage!
5053
bootc switch --transport containers-storage localhost/bootc-derived
54+
55+
# Also test that the mtime changes on modification
56+
let new_root_mtime = ls -Dl /ostree/bootc | get modified
57+
assert ($new_root_mtime > $orig_root_mtime)
58+
5159
# And reboot into it
5260
tmt-reboot
5361
}

0 commit comments

Comments
 (0)