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" edition = "2021"
[dependencies] [dependencies]
which = "7.0.1" which = "7.0.3"
log = "0.4.22" log = "0.4.27"
structopt = "0.3.26" structopt = "0.3.26"
tempfile = "3" tempfile = "3"
serde = { version = "1", features = ["derive"] } serde = { version = "1", features = ["derive"] }
toml = "0.8.19" toml = "0.8.22"
byte-unit = "5.1.6" byte-unit = "5.1.6"
nix = "0.29" nix = { version = "0.30.1", features = ["mount"] }
env_logger = "0.11.6" env_logger = "0.11.8"
pretty_env_logger = "0.5" pretty_env_logger = "0.5"
dialoguer = "0.11" dialoguer = "0.11"
console = "0.15.10" console = "0.15.11"
anyhow = "1" anyhow = "1"

View File

@ -6,7 +6,7 @@ use structopt::StructOpt;
/// Parse size argument as bytes /// Parse size argument as bytes
/// e.g. 10GB, 10GiB, etc. /// e.g. 10GB, 10GiB, etc.
fn parse_bytes(src: &str) -> Result<Byte, &'static str> { 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)] #[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")?; 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")?; .context("Error creating the image")?;
} }

View File

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

View File

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