Skip to content

Commit

Permalink
tools: forward config to children
Browse files Browse the repository at this point in the history
  • Loading branch information
losynix committed Jun 16, 2022
1 parent 5832437 commit e3f5c86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 7 deletions.
12 changes: 9 additions & 3 deletions usbsas-tools/src/imager.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ struct Imager {
}

impl Imager {
fn new(out_file: Option<fs::File>, busdevnum: Option<BusDevNum>) -> Result<Self> {
fn new(
config_path: &str,
out_file: Option<fs::File>,
busdevnum: Option<BusDevNum>,
) -> Result<Self> {
let mut pipes_read = vec![];
let mut pipes_write = vec![];

Expand All @@ -97,6 +101,7 @@ impl Imager {
// If busnum and devnum were not specified we need usbdev to select the device
let usbdev = if busdevnum.is_none() {
let usbdev = UsbsasChildSpawner::new()
.arg(config_path)
.spawn::<usbsas_usbdev::UsbDev, proto::usbdev::Request>()?;
pipes_read.push(usbdev.comm.input_fd());
pipes_write.push(usbdev.comm.output_fd());
Expand Down Expand Up @@ -323,6 +328,7 @@ fn main() -> Result<()> {
)
.get_matches();

let config_path = matches.get_one::<String>("config").unwrap();
let writer = if let Some(path) = matches.get_one::<&String>("output") {
match fs::File::create(path) {
Ok(file) => Some(file),
Expand All @@ -334,7 +340,7 @@ fn main() -> Result<()> {
} else if matches.contains_id("stdout") {
None
} else {
let config = conf_parse(&conf_read(matches.get_one::<&String>("config").unwrap())?)?;
let config = conf_parse(&conf_read(config_path)?)?;
let out_dir = path::Path::new(&config.out_directory);
let (out_file, out_path) = tempfile::Builder::new()
.prefix("device_image_")
Expand Down Expand Up @@ -362,7 +368,7 @@ fn main() -> Result<()> {
(None, None) => None,
};

let mut imager = Imager::new(writer, busdevnum)?;
let mut imager = Imager::new(config_path, writer, busdevnum)?;

if imager.busdevnum.is_none() {
imager.select_device()?;
Expand Down
19 changes: 15 additions & 4 deletions usbsas-tools/src/uploader.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,11 @@ protorequest!(
end = End[RequestEnd, ResponseEnd]
);

fn upload(bundle_path: &str, id: &str) -> Result<()> {
fn upload(config_path: &str, bundle_path: &str, id: &str) -> Result<()> {
use proto::uploader::response::Msg;
let mut uploader = UsbsasChildSpawner::new()
.arg(bundle_path)
.arg(config_path)
.spawn::<usbsas_net::Uploader, proto::uploader::Request>()?;

log::info!("Uploading bundle");
Expand Down Expand Up @@ -129,6 +130,15 @@ fn main() -> Result<()> {
let command = Command::new("usbsas-uploader")
.about("Test uploading or analyzing a usbsas bundle")
.version("1.0")
.arg(
clap::Arg::new("config")
.short('c')
.long("config")
.help("Path of the configuration file")
.takes_value(true)
.default_value(usbsas_utils::USBSAS_CONFIG)
.required(false),
)
.arg(
Arg::new("bundle")
.value_name("FILE")
Expand All @@ -152,14 +162,15 @@ fn main() -> Result<()> {
);

let matches = command.get_matches();
let config_path = matches.get_one::<String>("config").unwrap();

if let Some(path) = matches.get_one::<&String>("bundle") {
if let Some(id) = matches.get_one::<&String>("ID") {
if let Some(path) = matches.get_one::<String>("bundle") {
if let Some(id) = matches.get_one::<String>("ID") {
if matches.contains_id("analyze") {
analyze(path, id)?;
return Ok(());
}
upload(path, id)?;
upload(config_path, path, id)?;
}
}

Expand Down

0 comments on commit e3f5c86

Please sign in to comment.