Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

main: Add more error context #60

Merged
merged 1 commit into from
Oct 6, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions src/bootupd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ pub(crate) fn install(source_root: &str, dest_root: &str) -> Result<()> {
}

let sysroot = openat::Dir::open(dest_root)?;
update_state(&sysroot, &state)?;
update_state(&sysroot, &state).context("Failed to update state")?;

Ok(())
}
Expand Down Expand Up @@ -109,7 +109,7 @@ pub(crate) enum ComponentUpdateResult {
/// daemon implementation of component update
pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
let sysroot = openat::Dir::open("/")?;
let _lock = acquire_write_lock("/")?;
let _lock = acquire_write_lock("/").context("Failed to acquire write lock")?;
let mut state = get_saved_state("/")?.unwrap_or_else(|| SavedState {
..Default::default()
});
Expand All @@ -128,7 +128,7 @@ pub(crate) fn update(name: &str) -> Result<ComponentUpdateResult> {
let interrupted = pending_container.get(component.name()).cloned();

pending_container.insert(component.name().into(), update.clone());
update_state(&sysroot, &state)?;
update_state(&sysroot, &state).context("Failed to update state")?;
let newinst = component
.run_update(&inst)
.with_context(|| format!("Failed to update {}", component.name()))?;
Expand Down Expand Up @@ -160,7 +160,9 @@ pub(crate) fn validate(name: &str) -> Result<ValidationResult> {
fn update_state(sysroot_dir: &openat::Dir, state: &SavedState) -> Result<()> {
let subdir = sysroot_dir.sub_dir(STATEFILE_DIR)?;
let f = {
let f = subdir.new_unnamed_file(0o644)?;
let f = subdir
.new_unnamed_file(0o644)
.context("creating temp file")?;
let mut buff = std::io::BufWriter::new(f);
serde_json::to_writer(&mut buff, state)?;
buff.flush()?;
Expand All @@ -174,11 +176,17 @@ fn update_state(sysroot_dir: &openat::Dir, state: &SavedState) -> Result<()> {
};
let dest_tmp_name = Path::new(&dest_tmp_name);
if subdir.exists(dest_tmp_name)? {
subdir.remove_file(dest_tmp_name)?;
subdir
.remove_file(dest_tmp_name)
.context("Removing temp file")?;
}
subdir.link_file_at(&f, dest_tmp_name)?;
f.sync_all()?;
subdir.local_rename(dest_tmp_name, STATEFILE_NAME)?;
subdir
.link_file_at(&f, dest_tmp_name)
.context("Linking temp file")?;
f.sync_all().context("syncing")?;
subdir
.local_rename(dest_tmp_name, STATEFILE_NAME)
.context("Renaming temp file")?;
Ok(())
}

Expand Down