fixed bug introduced from removing requirement for 2 targets; critical bug fixed

This commit is contained in:
ascendforever 2023-10-24 19:19:12 -04:00
parent 71c8f1c3d5
commit 007a00910d
2 changed files with 30 additions and 26 deletions

Binary file not shown.

View file

@ -81,8 +81,11 @@ fn prompt_confirm(run_targets: &Vec<Vec<String>>) -> bool {
fn process_args() -> (Vec<Vec<PathBuf>>, Config) { fn process_args() -> (Vec<Vec<PathBuf>>, Config) {
let args = CLIArguments::from_args(); let args = CLIArguments::from_args();
let run_targets: Vec<Vec<String>> = split_vec(&args.targets, ";"); let run_targets: Vec<Vec<String>> = {
run_targets.retain(|targets| targets.len() > 0); let mut rt = split_vec(&args.targets, ";");
rt.retain(|targets| !targets.is_empty() );
rt
};
if args.prompt { if args.prompt {
if !prompt_confirm(&run_targets) { if !prompt_confirm(&run_targets) {
@ -91,8 +94,7 @@ fn process_args() -> (Vec<Vec<PathBuf>>, Config) {
} }
let run_paths: Vec<Vec<PathBuf>> = run_targets.iter().enumerate().map( let run_paths: Vec<Vec<PathBuf>> = run_targets.iter().enumerate().map(
|(i,spaths)| { |(_,spaths)| spaths.iter().map(
spaths.iter().map(
|spath| Path::new(spath).canonicalize().unwrap_or_else( |spath| Path::new(spath).canonicalize().unwrap_or_else(
|_| { |_| {
eprintln!("Failed to retrieve absolute path for {}", shlex::quote(spath)); eprintln!("Failed to retrieve absolute path for {}", shlex::quote(spath));
@ -100,7 +102,6 @@ fn process_args() -> (Vec<Vec<PathBuf>>, Config) {
} }
) )
).collect() ).collect()
}
).collect(); ).collect();
@ -116,26 +117,29 @@ fn process_args() -> (Vec<Vec<PathBuf>>, Config) {
}) })
} }
/// minimum length of slice = 2 fn get_st_dev(file: &PathBuf) -> u64 {
fn assert_all_same_device(paths: &[PathBuf]) { if let Ok(metadata) = std::fs::metadata(file) {
let first_device_id = if let Ok(metadata) = std::fs::metadata(&paths[0]) {
metadata.st_dev() metadata.st_dev()
} else { } else {
eprintln!("Failed to retrive device id for {}", shlex::quote(&paths[0].to_string_lossy())); eprintln!("Failed to retrive device id for {}", shlex::quote(&file.to_string_lossy()));
std::process::exit(1); std::process::exit(1);
}; }
for path in &paths[1..] { }
if let Ok(metadata) = std::fs::metadata(path) {
if metadata.st_dev() != first_device_id { /// minimum length of slice = 2
fn assert_all_same_device(paths: &[PathBuf]) {
if paths.len() <= 1 {
return
}
let first_device_id = get_st_dev(&paths[0]);
let wrong: Vec<&PathBuf> = paths[1..].iter().filter(|path| get_st_dev(path) == first_device_id).collect();
if !wrong.is_empty() {
for path in wrong {
eprintln!("Device ids must all be the same; got different for: {}", shlex::quote(&path.to_string_lossy())); eprintln!("Device ids must all be the same; got different for: {}", shlex::quote(&path.to_string_lossy()));
std::process::exit(1);
} }
} else {
eprintln!("Failed to retrive device id for {}", shlex::quote(&path.to_string_lossy()));
std::process::exit(1); std::process::exit(1);
} }
} }
}
/// perform a full run with pre-processed inputs /// perform a full run with pre-processed inputs
fn run(paths: Vec<PathBuf>, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> { fn run(paths: Vec<PathBuf>, cfg: &Config) -> Result<(), Box<dyn std::error::Error>> {