fix & update

This commit is contained in:
PurpleCow 2025-05-22 01:10:16 +02:00
parent df3b4c32a9
commit 37a086fb67
6 changed files with 271 additions and 367 deletions

610
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -5,16 +5,16 @@ authors = ["Roey Darwish Dror, PurpleCow"]
edition = "2021"
[dependencies]
which = "7.0.1"
log = "0.4.22"
which = "7.0.3"
log = "0.4.27"
structopt = "0.3.26"
tempfile = "3"
serde = { version = "1", features = ["derive"] }
toml = "0.8.19"
toml = "0.8.22"
byte-unit = "5.1.6"
nix = "0.29"
env_logger = "0.11.6"
nix = { version = "0.30.1", features = ["mount"] }
env_logger = "0.11.8"
pretty_env_logger = "0.5"
dialoguer = "0.11"
console = "0.15.10"
console = "0.15.11"
anyhow = "1"

View File

@ -6,7 +6,7 @@ use structopt::StructOpt;
/// Parse size argument as bytes
/// e.g. 10GB, 10GiB, etc.
fn parse_bytes(src: &str) -> Result<Byte, &'static str> {
Byte::from_str(src).map_err(|_| "Invalid image size")
Byte::parse_str(src, false).map_err(|_| "Invalid image size")
}
#[derive(StructOpt)]

View File

@ -78,7 +78,7 @@ fn create_image(path: &Path, size: Byte, overwrite: bool) -> anyhow::Result<Loop
}
let file = options.open(path).context("Error creating the image")?;
file.set_len(size.get_bytes() as u64)
file.set_len(size.as_u64())
.context("Error creating the image")?;
}

View File

@ -23,7 +23,7 @@ impl<'a> MountStack<'a> {
filesystem: &'a Filesystem,
target: PathBuf,
options: Option<&str>,
) -> nix::Result<()> {
) -> Result<(), nix::Error> {
let source = filesystem.block().path();
debug!("Mounting {:?} to {:?}", filesystem, target);
mount(
@ -42,7 +42,7 @@ impl<'a> MountStack<'a> {
source: PathBuf,
target: PathBuf,
options: Option<&str>,
) -> nix::Result<()> {
) -> Result<(), nix::Error> {
debug!("Mounting {:?} to {:?}", source, target);
mount::<_, _, str, _>(
Some(&source),

View File

@ -1,5 +1,5 @@
use anyhow::Context;
use byte_unit::Byte;
use byte_unit::{Byte, UnitType};
use std::{fmt, fs};
#[derive(Debug)]
@ -17,7 +17,7 @@ impl fmt::Display for Device {
"{} {} ({})",
self.vendor,
self.model,
self.size.get_appropriate_unit(true)
self.size.get_appropriate_unit(UnitType::Decimal)
)
}
}
@ -60,14 +60,14 @@ pub fn get_storage_devices(allow_non_removable: bool) -> anyhow::Result<Vec<Devi
vendor: fs::read_to_string(entry.path().join("device/vendor"))
.map(trimmed)
.context("Error querying storage devices")?,
size: Byte::from_bytes(
size: Byte::from_u128(
fs::read_to_string(entry.path().join("size"))
.context("Error querying storage devices")?
.trim()
.parse::<u128>()
.context("Could not parse block size to unsigned integer (u128)")?
* 512,
),
).expect("Invalid byte size"),
});
}