better error reporting in proc skel

rust
Avril 4 years ago
parent c5cf1106c3
commit 24475646a1
Signed by: flanchan
GPG Key ID: 284488987C31F630

@ -1,7 +1,7 @@
#![allow(dead_code)] #![allow(dead_code)]
#[cfg(feature="deferred-drop")] #[macro_use] extern crate lazy_static; #[macro_use] extern crate lazy_static;
#[macro_use] extern crate cfg_if; #[macro_use] extern crate cfg_if;
#[macro_use] mod ext; use ext::*; #[macro_use] mod ext; use ext::*;
@ -17,7 +17,7 @@ use arg::Mode;
/// ///
/// # Method /// # Method
/// On `Err`, print the error message and then exit with error code provided /// On `Err`, print the error message and then exit with error code provided
fn handle_err_fatal<T, E>(op: Result<T, E>, errcd: i32) -> T #[inline] fn handle_err_fatal<T, E>(op: Result<T, E>, errcd: i32) -> T
where E: std::error::Error where E: std::error::Error
{ {
match op match op

@ -11,12 +11,12 @@ pub enum ModeKind
Unshuffle Unshuffle
} }
pub fn shuffle_file(file: impl AsRef<Path>) -> io::Result<()> pub fn shuffle_file_ip(file: impl AsRef<Path>) -> io::Result<()>
{ {
todo!() todo!()
} }
pub fn unshuffle_file(file: impl AsRef<Path>) -> io::Result<()> pub fn unshuffle_file_ip(file: impl AsRef<Path>) -> io::Result<()>
{ {
todo!() todo!()
} }
@ -25,6 +25,40 @@ pub fn unshuffle_file(file: impl AsRef<Path>) -> io::Result<()>
pub fn process_files_ip<I>(files: I, mode: ModeKind) -> io::Result<()> pub fn process_files_ip<I>(files: I, mode: ModeKind) -> io::Result<()>
where I: IntoIterator<Item = PathBuf> where I: IntoIterator<Item = PathBuf>
{ {
cfg_if! {
if #[cfg(feature="threads")] {
let handles: Vec<_> = files.into_iter().map(|file| {
std::thread::spawn(move || {
let res = match mode {
ModeKind::Shuffle => shuffle_file_ip(&file),
ModeKind::Unshuffle => unshuffle_file_ip(&file),
};
(res, file)
})
}).collect();
todo!() for h in handles
{
let (res, file) = h.join().expect("Worker thread panicked"); // TODO: How do we communicate which thread failed here? Should we even try?
res.map_err(move |x| {
eprintln!("Failed to process {:?}", file);
x
})?;
}
Ok(())
} else {
for file in files.into_iter() {
let res = match mode {
ModeKind::Shuffle => shuffle_file_ip(&file),
ModeKind::Unshuffle => unshuffle_file_ip(&file),
};
res.map_err(move |x| {
eprintln!("Failed to process {:?}", file);
x
})?;
}
Ok(())
}
}
} }

Loading…
Cancel
Save