From 8fa6e4a5622cfe47d8ee5d2a72d9d33ac7f0e63c Mon Sep 17 00:00:00 2001 From: mulhern Date: Thu, 5 Dec 2024 09:53:19 -0500 Subject: [PATCH] Require a PathBuf for blockdev argument Signed-off-by: mulhern --- src/bin/tools/cmds.rs | 6 ++++-- src/bin/tools/dump_metadata.rs | 3 ++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/src/bin/tools/cmds.rs b/src/bin/tools/cmds.rs index 8f6384a1a7..792c539486 100644 --- a/src/bin/tools/cmds.rs +++ b/src/bin/tools/cmds.rs @@ -2,6 +2,8 @@ // License, v. 2.0. If a copy of the MPL was not distributed with this // file, You can obtain one at http://mozilla.org/MPL/2.0/. +use std::path::PathBuf; + use clap::{Arg, ArgAction, Command}; use crate::tools::dump_metadata; @@ -19,6 +21,7 @@ impl StratisDumpMetadata { .next_line_help(true) .arg( Arg::new("dev") + .value_parser(clap::value_parser!(PathBuf)) .required(true) .help("Print metadata of given device"), ) @@ -49,8 +52,7 @@ impl<'a> ToolCommand<'a> for StratisDumpMetadata { fn run(&self, command_line_args: Vec) -> Result<(), String> { let matches = StratisDumpMetadata::cmd().get_matches_from(command_line_args); let devpath = matches - .get_one::("dev") - .map(|s| s.as_str()) + .get_one::("dev") .expect("'dev' is a mandatory argument"); dump_metadata::run( diff --git a/src/bin/tools/dump_metadata.rs b/src/bin/tools/dump_metadata.rs index 7fc2dfe70f..1a8c8f58d8 100644 --- a/src/bin/tools/dump_metadata.rs +++ b/src/bin/tools/dump_metadata.rs @@ -5,6 +5,7 @@ use std::{ fs::OpenOptions, io::{Seek, SeekFrom}, + path::PathBuf, }; use pretty_hex::pretty_hex; @@ -111,7 +112,7 @@ fn print_pool_metadata(pool_metadata: &Option>, only_pool: bool) -> Resu // Otherwise display the StaticHeader fields of both sigblocks. // If print_bytes flag is set to True, display the bytes buffer // of the sigblock alongside the StaticHeader. -pub fn run(devpath: &str, print_bytes: bool, pool_only: bool) -> Result<(), String> { +pub fn run(devpath: &PathBuf, print_bytes: bool, pool_only: bool) -> Result<(), String> { let mut devfile = OpenOptions::new() .read(true) .open(devpath)