Skip to content

Commit 839be56

Browse files
authored
Merge pull request #47 from cgwalters/task-root
task: Add root parameter
2 parents f0cf4b0 + 6e5d32e commit 839be56

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

lib/src/install.rs

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -255,6 +255,7 @@ async fn initialize_ostree_root_from_self(
255255
root_setup: &RootSetup,
256256
kargs: &[&str],
257257
) -> Result<InstallAleph> {
258+
let rootfs_dir = &root_setup.rootfs_fd;
258259
let rootfs = root_setup.rootfs.as_path();
259260
let opts = &state.opts;
260261
let cancellable = gio::Cancellable::NONE;
@@ -312,18 +313,17 @@ async fn initialize_ostree_root_from_self(
312313
["admin", "init-fs", "--modern", rootfs.as_str()],
313314
)?;
314315

315-
let repopath = &rootfs.join("ostree/repo");
316316
for (k, v) in [("sysroot.bootloader", "none"), ("sysroot.readonly", "true")] {
317317
Task::new("Configuring ostree repo", "ostree")
318-
.args(["config", "--repo", repopath.as_str(), "set", k, v])
318+
.args(["config", "--repo", "ostree/repo", "set", k, v])
319+
.root(rootfs_dir)?
319320
.quiet()
320321
.run()?;
321322
}
322-
Task::new_and_run(
323-
"Initializing sysroot",
324-
"ostree",
325-
["admin", "os-init", stateroot, "--sysroot", rootfs.as_str()],
326-
)?;
323+
Task::new("Initializing sysroot", "ostree")
324+
.args(["admin", "os-init", stateroot, "--sysroot", "."])
325+
.root(rootfs_dir)?
326+
.run()?;
327327

328328
// Ensure everything in the ostree repo is labeled
329329
lsm_label(&rootfs.join("ostree"), "/usr".into(), true)?;
@@ -376,9 +376,7 @@ async fn initialize_ostree_root_from_self(
376376
.ok_or_else(|| anyhow::anyhow!("Failed to find deployment"))?;
377377
// SAFETY: There must be a path
378378
let path = sysroot.deployment_dirpath(&deployment).unwrap();
379-
let sysroot_dir = cap_std::fs::Dir::open_ambient_dir(rootfs, cap_std::ambient_authority())
380-
.context("Opening rootfs")?;
381-
let root = sysroot_dir
379+
let root = rootfs_dir
382380
.open_dir(path.as_str())
383381
.context("Opening deployment dir")?;
384382
let mut f = {
@@ -782,11 +780,10 @@ pub(crate) async fn install(opts: InstallOpts) -> Result<()> {
782780
println!("Installed Ignition config from {ignition_file}");
783781
}
784782

785-
Task::new_and_run(
786-
"Setting root immutable bit",
787-
"chattr",
788-
["+i", rootfs.rootfs.as_str()],
789-
)?;
783+
Task::new("Setting root immutable bit", "chattr")
784+
.root(&rootfs.rootfs_fd)?
785+
.args(["+i", "."])
786+
.run()?;
790787

791788
Task::new_and_run("Trimming filesystems", "fstrim", ["-a", "-v"])?;
792789

lib/src/task.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ use std::{
55
};
66

77
use anyhow::{Context, Result};
8+
use cap_std::fs::Dir;
9+
use cap_std_ext::cap_std;
10+
use cap_std_ext::prelude::CapStdExtCommandExt;
811

912
pub(crate) struct Task {
1013
description: String,
@@ -18,6 +21,11 @@ impl Task {
1821
Self::new_cmd(description, Command::new(exe.as_ref()))
1922
}
2023

24+
pub(crate) fn root(mut self, dir: &Dir) -> Result<Self> {
25+
self.cmd.cwd_dir(dir.try_clone()?);
26+
Ok(self)
27+
}
28+
2129
pub(crate) fn new_cmd(description: impl AsRef<str>, mut cmd: Command) -> Self {
2230
let description = description.as_ref().to_string();
2331
// Default to noninteractive

0 commit comments

Comments
 (0)