Forum | Documentation | Website | Blog

Skip to content
Snippets Groups Projects
Verified Commit 1c58c202 authored by Ayush Singh's avatar Ayush Singh
Browse files

bb-imager: Make udisks2 optional


- Do not use udisks2 in CLI.
- Shaves off 50 dependencies in CLI, so pretty nice.

Signed-off-by: Ayush Singh's avatarAyush Singh <ayush@beagleboard.org>
parent cd09f941
Branches
Tags
1 merge request!44bb-imager: Featuregate more things
......@@ -33,3 +33,6 @@ assets = [
[features]
pb2_mspm0 = ["bb-imager/pb2_mspm0_dbus"]
[target.'cfg(target_os = "linux")'.dependencies]
bb-imager = { path = "../bb-imager", version = "0.0.3", features = ["udisks2"] }
......@@ -35,9 +35,9 @@ cfg-if = "1.0.0"
bb-imager-flasher-pb2-mspm0 = { path = "../bb-imager-flasher-pb2-mspm0", optional = true }
zbus = { version = "5.3.0", default-features = false, features = ["tokio"], optional = true}
serde_with = "3.12.0"
udisks2 = { version = "0.1.0", optional = true }
[target.'cfg(target_os = "linux")'.dependencies]
udisks2 = "0.1.0"
tokio-serial = { version = "5.4.4", features = ["libudev"] }
[target.'cfg(windows)'.dependencies]
......
use thiserror::Error;
#[cfg(feature = "udisks2")]
use std::{
collections::HashMap,
os::fd::{FromRawFd, IntoRawFd},
......@@ -9,11 +10,14 @@ use std::{
pub enum Error {
#[error("Failed to open destination {0}")]
FailedToOpenDestionation(String),
#[error("Formatting failed: {0}")]
FailedToFormat(String),
#[error("Zbus Error: {0}")]
#[cfg(target_os = "linux")]
#[cfg(feature = "udisks2")]
DbusClientError(#[from] udisks2::zbus::Error),
}
#[cfg(feature = "udisks2")]
pub(crate) async fn format_sd(dst: &str) -> crate::error::Result<()> {
let dbus_client = udisks2::Client::new().await.map_err(Error::from)?;
......@@ -45,6 +49,7 @@ pub(crate) async fn format_sd(dst: &str) -> crate::error::Result<()> {
Ok(())
}
#[cfg(feature = "udisks2")]
pub(crate) async fn open_sd(dst: &str) -> crate::error::Result<tokio::fs::File> {
let dbus_client = udisks2::Client::new().await.map_err(Error::from)?;
......@@ -73,3 +78,28 @@ pub(crate) async fn open_sd(dst: &str) -> crate::error::Result<tokio::fs::File>
Ok(unsafe { tokio::fs::File::from_raw_fd(std::os::fd::OwnedFd::from(fd).into_raw_fd()) })
}
#[cfg(not(feature = "udisks2"))]
pub(crate) async fn open_sd(dst: &str) -> crate::error::Result<tokio::fs::File> {
tokio::fs::OpenOptions::new()
.read(true)
.write(true)
.create(false)
.open(dst)
.await
.map_err(Into::into)
}
#[cfg(not(feature = "udisks2"))]
pub(crate) async fn format_sd(dst: &str) -> crate::error::Result<()> {
let output = tokio::process::Command::new("mkfs.vfat")
.arg(dst)
.output()
.await?;
if output.status.success() {
Ok(())
} else {
Err(Error::FailedToFormat(String::from_utf8(output.stderr).unwrap()).into())
}
}
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment