Skip to content

Commit 0886b20

Browse files
authored
Merge pull request #1264 from ckyrouac/redeploy-bug-fix
Redeploy bug fix
2 parents 7505150 + dbae495 commit 0886b20

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

lib/src/install.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -680,17 +680,25 @@ async fn initialize_ostree_root(
680680
ostree_ext::fsverity::ensure_verity(repo).await?;
681681
}
682682

683-
let stateroot_exists = rootfs_dir.try_exists(format!("ostree/deploy/{stateroot}"))?;
684-
ensure!(
685-
!stateroot_exists,
686-
"Cannot redeploy over extant stateroot {stateroot}"
687-
);
688-
sysroot
689-
.init_osname(stateroot, cancellable)
690-
.context("initializing stateroot")?;
683+
if let Some(booted) = sysroot.booted_deployment() {
684+
if stateroot == booted.stateroot() {
685+
anyhow::bail!("Cannot redeploy over booted stateroot {stateroot}");
686+
}
687+
}
691688

692689
let sysroot_dir = crate::utils::sysroot_dir(&sysroot)?;
693690

691+
// init_osname fails when ostree/deploy/{stateroot} already exists
692+
// the stateroot directory can be left over after a failed install attempt,
693+
// so only create it via init_osname if it doesn't exist
694+
// (ideally this would be handled by init_osname)
695+
let stateroot_path = format!("ostree/deploy/{stateroot}");
696+
if !sysroot_dir.try_exists(stateroot_path)? {
697+
sysroot
698+
.init_osname(stateroot, cancellable)
699+
.context("initializing stateroot")?;
700+
}
701+
694702
state.tempdir.create_dir("temp-run")?;
695703
let temp_run = state.tempdir.open_dir("temp-run")?;
696704

lib/src/store/mod.rs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::env;
33
use std::ops::Deref;
44

55
use anyhow::{Context, Result};
6+
use cap_std_ext::cap_std;
67
use cap_std_ext::cap_std::fs::Dir;
78
use cap_std_ext::dirext::CapStdExtDirExt;
89
use clap::ValueEnum;
@@ -88,15 +89,18 @@ impl Storage {
8889
}
8990
let sysroot_dir = crate::utils::sysroot_dir(&self.sysroot)?;
9091

91-
if self.sysroot.booted_deployment().is_none() {
92-
anyhow::bail!("Not a bootc system (this shouldn't be possible)");
93-
}
94-
95-
// load the sepolicy from the booted ostree deployment so the imgstorage can be
96-
// properly labeled with /var/lib/container/storage labels
97-
let dep = self.sysroot.booted_deployment().unwrap();
98-
let dep_fs = deployment_fd(&self.sysroot, &dep)?;
99-
let sepolicy = &ostree::SePolicy::new_at(dep_fs.as_raw_fd(), gio::Cancellable::NONE)?;
92+
let sepolicy = if self.sysroot.booted_deployment().is_none() {
93+
// fallback to policy from container root
94+
// this should only happen during cleanup of a broken install
95+
let container_root = Dir::open_ambient_dir("/", cap_std::ambient_authority())?;
96+
&ostree::SePolicy::new_at(container_root.as_raw_fd(), gio::Cancellable::NONE)?
97+
} else {
98+
// load the sepolicy from the booted ostree deployment so the imgstorage can be
99+
// properly labeled with /var/lib/container/storage labels
100+
let dep = self.sysroot.booted_deployment().unwrap();
101+
let dep_fs = deployment_fd(&self.sysroot, &dep)?;
102+
&ostree::SePolicy::new_at(dep_fs.as_raw_fd(), gio::Cancellable::NONE)?
103+
};
100104

101105
let imgstore = crate::imgstorage::Storage::create(&sysroot_dir, &self.run, Some(sepolicy))?;
102106
Ok(self.imgstore.get_or_init(|| imgstore))

0 commit comments

Comments
 (0)