|
|
|
@ -59,12 +59,12 @@ async fn do_work(process: impl AsRef<Path>, file: impl AsRef<OsStr>, mut prog: P
|
|
|
|
|
if err {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let value = format!("[!] {:?}: {}", file, value);
|
|
|
|
|
let value = format!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
if let Err(_) = prog.eprintln(&value[..]).await {
|
|
|
|
|
eprintln!("\n{}", value);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
eprintln!("[!] {:?}: {}", file, value);
|
|
|
|
|
eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::BrightYellow), "!"), file, colour::style(colour!(Color::Yellow),value));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
@ -127,67 +127,72 @@ where I: IntoIterator<Item=T>,
|
|
|
|
|
})
|
|
|
|
|
};
|
|
|
|
|
let mut i=0usize;
|
|
|
|
|
let results = join_all(files
|
|
|
|
|
.map(|filename| {
|
|
|
|
|
let semaphore = semaphore.clone();
|
|
|
|
|
let process = Arc::clone(&process);
|
|
|
|
|
let mut tx = tx.clone();
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="progress")] let mut progress = progress.clone();
|
|
|
|
|
|
|
|
|
|
(tokio::spawn(async move {
|
|
|
|
|
#[cfg(feature="progress")] type Opt<T> = OptionFuture<T>;
|
|
|
|
|
#[cfg(not(feature="progress"))] type Opt<T> = std::marker::PhantomData<T>;
|
|
|
|
|
let _task_id: Opt<_> = {
|
|
|
|
|
let _lock = maybe_await(semaphore.map(|x| x.acquire_owned())).await;
|
|
|
|
|
let results =
|
|
|
|
|
join_all(
|
|
|
|
|
files
|
|
|
|
|
.map(|filename| {
|
|
|
|
|
let semaphore = semaphore.clone();
|
|
|
|
|
let process = Arc::clone(&process);
|
|
|
|
|
let mut tx = tx.clone();
|
|
|
|
|
|
|
|
|
|
#[cfg(feature="progress")] let mut progress = progress.clone();
|
|
|
|
|
|
|
|
|
|
(tokio::spawn(async move {
|
|
|
|
|
#[cfg(feature="progress")] type Opt<T> = OptionFuture<T>;
|
|
|
|
|
#[cfg(not(feature="progress"))] type Opt<T> = std::marker::PhantomData<T>;
|
|
|
|
|
let _task_id: Opt<_> = {
|
|
|
|
|
let _lock = maybe_await(semaphore.map(|x| x.acquire_owned())).await;
|
|
|
|
|
|
|
|
|
|
// (task_id, worker_result)
|
|
|
|
|
let worker = {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let worker = do_work(process.as_ref(), &filename, progress.clone());
|
|
|
|
|
let task = progress.add_task(format!("{:?}", filename.as_ref()));
|
|
|
|
|
future::join(task, worker).await
|
|
|
|
|
} else {
|
|
|
|
|
#[cfg(nightly)] type NoReturn = !;
|
|
|
|
|
#[cfg(not(nightly))] type NoReturn = ();
|
|
|
|
|
(Option::<NoReturn>::None, do_work(process.as_ref(), &filename, ()).await)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
// (task_id, worker_result)
|
|
|
|
|
let worker = {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
let worker = do_work(process.as_ref(), &filename, progress.clone());
|
|
|
|
|
let task = progress.add_task(format!("{:?}", filename.as_ref()));
|
|
|
|
|
future::join(task, worker).await
|
|
|
|
|
} else {
|
|
|
|
|
#[cfg(nightly)] type NoReturn = !;
|
|
|
|
|
#[cfg(not(nightly))] type NoReturn = ();
|
|
|
|
|
(Option::<NoReturn>::None, do_work(process.as_ref(), &filename, ()).await)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
match worker.1 {
|
|
|
|
|
Ok(strings) => tx.send((filename, strings, i)).await.map_err(|_| "Child panic").unwrap(),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
#[cfg(not(feature="progress"))] eprintln!("[!] {:?}: {}", filename.as_ref(), error);
|
|
|
|
|
#[cfg(feature="progress")] let _ = progress.eprintln(format!("[!] ({}) {:?}: {}", i, filename.as_ref(), error)).await.or_else(|e| {eprintln!("\n{}",e); Err(e)});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
worker.0.ok().into()
|
|
|
|
|
} else {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(nightly)] {
|
|
|
|
|
std::marker::PhantomData::<!>
|
|
|
|
|
} else {
|
|
|
|
|
std::marker::PhantomData::<()>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
match worker.1 {
|
|
|
|
|
Ok(strings) => tx.send((filename, strings, i)).await.map_err(|_| "Child panic").unwrap(),
|
|
|
|
|
Err(error) => {
|
|
|
|
|
#[cfg(not(feature="progress"))] eprintln!("[{}] {:?}: {}", colour::style(colour!(Color::Yellow),"!"), filename.as_ref(), colour::style(colour!(Color::Yellow), error));
|
|
|
|
|
#[cfg(feature="progress")] let _ = progress.eprintln(format!("[{}] ({}) {:?}: {}", colour::style(colour!(Color::Yellow),"!"),i, filename.as_ref(), colour::style(colour!(Color::Yellow), error))).await
|
|
|
|
|
.or_else(|e| {
|
|
|
|
|
eprintln!("\n{}",e); Err(e)
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(feature="progress")] {
|
|
|
|
|
worker.0.ok().into()
|
|
|
|
|
} else {
|
|
|
|
|
cfg_if!{
|
|
|
|
|
if #[cfg(nightly)] {
|
|
|
|
|
std::marker::PhantomData::<!>
|
|
|
|
|
} else {
|
|
|
|
|
std::marker::PhantomData::<()>
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#[cfg(feature="progress")]
|
|
|
|
|
if let Some(Ok(id)) = _task_id.await {
|
|
|
|
|
let mut builder = progress.builder();
|
|
|
|
|
builder.bump_min(1);
|
|
|
|
|
builder.remove_task(id);
|
|
|
|
|
let _ = builder.send().await;
|
|
|
|
|
} else {
|
|
|
|
|
let _ = progress.bump_min(1).await;
|
|
|
|
|
}
|
|
|
|
|
}),i+=1).0
|
|
|
|
|
})).await
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
#[cfg(feature="progress")]
|
|
|
|
|
if let Some(Ok(id)) = _task_id.await {
|
|
|
|
|
let mut builder = progress.builder();
|
|
|
|
|
builder.bump_min(1);
|
|
|
|
|
builder.remove_task(id);
|
|
|
|
|
let _ = builder.send().await;
|
|
|
|
|
} else {
|
|
|
|
|
let _ = progress.bump_min(1).await;
|
|
|
|
|
}
|
|
|
|
|
}),i+=1).0
|
|
|
|
|
})).await
|
|
|
|
|
.into_iter()
|
|
|
|
|
.filter_map(|x| x.err());
|
|
|
|
|
|
|
|
|
|