Skip to content

Commit

Permalink
Switch a few Task users to direct Command
Browse files Browse the repository at this point in the history
I never intended the `Task` abstraction to be "the one way to
run subprocesses in bootc"...let's stop using it where:

- We're using `.quiet()` by default so we're not printing the
  description anyways, which is the *main* thing Task does
- We want to parse JSON, where we have a nice new helper

Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Jul 31, 2024
1 parent 3e89f8a commit 89aacb7
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
13 changes: 6 additions & 7 deletions lib/src/mount.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
//! Helpers for interacting with mountpoints
use anyhow::{anyhow, Context, Result};
use std::process::Command;

use anyhow::{anyhow, Result};
use camino::Utf8Path;
use fn_error_context::context;
use serde::Deserialize;

use crate::task::Task;
use crate::{cmdutils::CommandRunExt, task::Task};

#[derive(Deserialize, Debug)]
#[serde(rename_all = "kebab-case")]
Expand All @@ -26,8 +28,7 @@ pub(crate) struct Findmnt {
}

fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
let desc = format!("Inspecting {path}");
let o = Task::new(desc, "findmnt")
let o: Findmnt = Command::new("findmnt")
.args([
"-J",
"-v",
Expand All @@ -36,9 +37,7 @@ fn run_findmnt(args: &[&str], path: &str) -> Result<Filesystem> {
])
.args(args)
.arg(path)
.quiet()
.read()?;
let o: Findmnt = serde_json::from_str(&o).context("Parsing findmnt output")?;
.run_and_parse_json()?;
o.filesystems
.into_iter()
.next()
Expand Down
10 changes: 3 additions & 7 deletions lib/src/podman.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ use camino::Utf8Path;
use cap_std_ext::cap_std::fs::Dir;
use serde::Deserialize;

use crate::task::Task;

/// Where we look inside our container to find our own image
/// for use with `bootc install`.
pub(crate) const CONTAINER_STORAGE: &str = "/var/lib/containers";
Expand All @@ -26,12 +24,10 @@ pub(crate) struct ImageListEntry {
/// Given an image ID, return its manifest digest
#[cfg(feature = "install")]
pub(crate) fn imageid_to_digest(imgid: &str) -> Result<String> {
use crate::install::run_in_host_mountns;
let out = Task::new_cmd("podman inspect", run_in_host_mountns("podman"))
use crate::cmdutils::CommandRunExt;
let o: Vec<Inspect> = crate::install::run_in_host_mountns("podman")
.args(["inspect", imgid])
.quiet()
.read()?;
let o: Vec<Inspect> = serde_json::from_str(&out)?;
.run_and_parse_json()?;
let i = o
.into_iter()
.next()
Expand Down

0 comments on commit 89aacb7

Please sign in to comment.