Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
Signed-off-by: Colin Walters <[email protected]>
  • Loading branch information
cgwalters committed Aug 15, 2024
1 parent 4fed0e4 commit 40ff1d0
Show file tree
Hide file tree
Showing 5 changed files with 55 additions and 18 deletions.
15 changes: 15 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["cli", "lib", "xtask", "tests-integration"]
members = ["cli", "lib", "blockdev", "xtask", "tests-integration"]
resolver = "2"

[profile.dev]
Expand Down
25 changes: 25 additions & 0 deletions blockdev/Cargo.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
[package]
description = "Internal blockdev code"
# Should never be published to crates.io
publish = false
edition = "2021"
license = "MIT OR Apache-2.0"
name = "blockdev"
repository = "https://github.com/containers/bootc"
version = "0.0.0"

[dependencies]
anyhow = { workspace = true }
bootc-utils = { path = "../utils" }
camino = { workspace = true, features = ["serde1"] }
fn-error-context = { workspace = true }
regex = "1.10.4"
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
tracing = { workspace = true }

[dev-dependencies]
indoc = "2.0.5"

[lib]
path = "src/blockdev.rs"
16 changes: 3 additions & 13 deletions lib/src/blockdev.rs → blockdev/src/blockdev.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use regex::Regex;
use serde::Deserialize;

use crate::install::run_in_host_mountns;
use crate::task::Task;
use bootc_utils::CommandRunExt;

#[derive(Debug, Deserialize)]
Expand Down Expand Up @@ -84,15 +83,6 @@ impl Device {
}
}
#[context("Failed to wipe {dev}")]
pub(crate) fn wipefs(dev: &Utf8Path) -> Result<()> {
Task::new_and_run(
format!("Wiping device {dev}"),
"wipefs",
["-a", dev.as_str()],
)
}

#[context("Listing device {dev}")]
pub(crate) fn list_dev(dev: &Utf8Path) -> Result<Device> {
let mut devs: DevicesOutput = Command::new("lsblk")
Expand Down Expand Up @@ -176,10 +166,10 @@ impl Partition {

#[context("Listing partitions of {dev}")]
pub(crate) fn partitions_of(dev: &Utf8Path) -> Result<PartitionTable> {
let o = Task::new_quiet("sfdisk")
let o: SfDiskOutput = Command::new("sfdisk")
.args(["-J", dev.as_str()])
.read()?;
let o: SfDiskOutput = serde_json::from_str(&o).context("Parsing sfdisk output")?;
.run_and_parse_json()
.context("Parsing sfdisk output")?;
Ok(o.partitiontable)
}

Expand Down
15 changes: 11 additions & 4 deletions lib/src/install/baseline.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,15 @@ fn mkfs<'a>(
Ok(u)
}

#[context("Failed to wipe {dev}")]
fn wipefs(dev: &Utf8Path) -> Result<()> {
Task::new_and_run(
format!("Wiping device {dev}"),
"wipefs",
["-a", dev.as_str()],
)
}

#[context("Creating rootfs")]
pub(crate) fn install_create_rootfs(
state: &State,
Expand All @@ -184,11 +193,9 @@ pub(crate) fn install_create_rootfs(
let dev = &opts.device;
for child in device.children.iter().flatten() {
let child = child.path();
println!("Wiping {child}");
crate::blockdev::wipefs(Utf8Path::new(&child))?;
wipefs(Utf8Path::new(&child))?;
}
println!("Wiping {dev}");
crate::blockdev::wipefs(dev)?;
wipefs(dev)?;
} else if device.has_children() {
anyhow::bail!(
"Detected existing partitions on {}; use e.g. `wipefs` if you intend to overwrite",
Expand Down

0 comments on commit 40ff1d0

Please sign in to comment.