|
|
|
@ -88,10 +88,13 @@ async fn main() -> Result<(), Box<dyn std::error::Error>>
|
|
|
|
|
fs::{
|
|
|
|
|
OpenOptions,
|
|
|
|
|
},
|
|
|
|
|
sync,
|
|
|
|
|
sync::{
|
|
|
|
|
Mutex
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
use std::{
|
|
|
|
|
path::Path,
|
|
|
|
|
sync::Arc,
|
|
|
|
|
};
|
|
|
|
|
let args = parse_args().into_string()?;
|
|
|
|
|
let lmode = &args.mode.logging_mode;
|
|
|
|
@ -110,9 +113,10 @@ async fn main() -> Result<(), Box<dyn std::error::Error>>
|
|
|
|
|
if load.is_file() {
|
|
|
|
|
if let Some(mut file) = OpenOptions::new()
|
|
|
|
|
.read(true)
|
|
|
|
|
.open(load).await.log_and_forget(lmode, log::Level::Warning)
|
|
|
|
|
.open(load).await.log_and_forget(lmode, log::Level::Warning)?
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
log!(Info, lmode => "Hashes loading from {:?}", load);
|
|
|
|
|
args.mode.error_mode.handle(hashes.load_async(&mut file).await).log_and_forget(lmode, log::Level::Warning)?;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log!(Warning, lmode => "Exclusing directory from load path {:?}", load);
|
|
|
|
@ -122,24 +126,122 @@ async fn main() -> Result<(), Box<dyn std::error::Error>>
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log!(Debug, lmode => "Loaded hashes: {:?}", hashes);
|
|
|
|
|
log!(Info, lmode => "Starting checks (threaded)");
|
|
|
|
|
let hashes = Arc::new(Mutex::new(hashes));
|
|
|
|
|
for path in args.paths.iter()
|
|
|
|
|
{
|
|
|
|
|
let path = Path::new(path);
|
|
|
|
|
if path.is_dir() {
|
|
|
|
|
log!(Debug, lmode => "Spawning for {:?}", path);
|
|
|
|
|
let mode = args.mode.clone();
|
|
|
|
|
let path = path.to_owned();
|
|
|
|
|
let hashes= Arc::clone(&hashes);
|
|
|
|
|
children.push(tokio::task::spawn(async move {
|
|
|
|
|
//proc::do_dir_async()
|
|
|
|
|
log!(Debug, mode.logging_mode => " + {:?}", path);
|
|
|
|
|
let res = mode.error_mode.handle(proc::do_dir_async(path.clone(), 0, hashes, mode.clone()).await).log_and_forget(&mode.logging_mode, log::Level::Error);
|
|
|
|
|
log!(Info, mode.logging_mode => " - {:?}", path);
|
|
|
|
|
res
|
|
|
|
|
}));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
log!(Info, lmode => "Waiting on children");
|
|
|
|
|
let mut done = proc::DupeCount::default();
|
|
|
|
|
for child in children.into_iter()
|
|
|
|
|
{
|
|
|
|
|
done += args.mode.error_mode.handle(child.await?)?.unwrap_or_default().unwrap_or_default().unwrap_or_default();
|
|
|
|
|
}
|
|
|
|
|
log!(Info, lmode => "Found: {:?}", done);
|
|
|
|
|
|
|
|
|
|
let hashes = hashes.lock().await;
|
|
|
|
|
log!(Debug, lmode => "New hashes: {:?}", hashes);
|
|
|
|
|
|
|
|
|
|
for save in args.save.iter()
|
|
|
|
|
{
|
|
|
|
|
let save = Path::new(save);
|
|
|
|
|
log!(Info, lmode => "Saving hashes to {:?}", save);
|
|
|
|
|
if let Some(mut file) = OpenOptions::new()
|
|
|
|
|
.create(true)
|
|
|
|
|
//.append(true)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.write(true)
|
|
|
|
|
.open(save).await.log_and_forget(lmode, log::Level::Warning)?
|
|
|
|
|
{
|
|
|
|
|
args.mode.error_mode.handle(hashes.save_async(&mut file).await).log_and_forget(lmode, log::Level::Warning)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[cfg(not(feature="threads"))]
|
|
|
|
|
fn main() -> Result<(), error::Error>
|
|
|
|
|
fn main() -> Result<(), Box<dyn std::error::Error>>
|
|
|
|
|
{
|
|
|
|
|
let args = parse_args()?;
|
|
|
|
|
use std::{
|
|
|
|
|
path::Path,
|
|
|
|
|
fs::{
|
|
|
|
|
OpenOptions,
|
|
|
|
|
},
|
|
|
|
|
};
|
|
|
|
|
let args = parse_args().into_string()?;
|
|
|
|
|
let lmode = &args.mode.logging_mode;
|
|
|
|
|
|
|
|
|
|
log!(Debug, lmode => "Args parsed: {:?}", args);
|
|
|
|
|
|
|
|
|
|
let mut hashes = container::DupeMap::new();
|
|
|
|
|
|
|
|
|
|
// Load hashes
|
|
|
|
|
for load in args.load.iter()
|
|
|
|
|
{
|
|
|
|
|
let load = Path::new(load);
|
|
|
|
|
if load.exists() {
|
|
|
|
|
if load.is_file() {
|
|
|
|
|
if let Some(mut file) = OpenOptions::new()
|
|
|
|
|
.read(true)
|
|
|
|
|
.open(load).log_and_forget(lmode, log::Level::Warning)?
|
|
|
|
|
{
|
|
|
|
|
log!(Info, lmode => "Hashes loading from {:?}", load);
|
|
|
|
|
args.mode.error_mode.handle(hashes.load(&mut file)).log_and_forget(lmode, log::Level::Warning)?;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log!(Warning, lmode => "Exclusing directory from load path {:?}", load);
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
log!(Info, lmode => "Ignoring non-existant load path {:?}", load);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log!(Debug, lmode => "Loaded hashes: {:?}", hashes);
|
|
|
|
|
log!(Info, lmode => "Starting checks (threaded)");
|
|
|
|
|
|
|
|
|
|
let mut done = proc::DupeCount::default();
|
|
|
|
|
for path in args.paths.iter()
|
|
|
|
|
{
|
|
|
|
|
let path = Path::new(path);
|
|
|
|
|
if path.is_dir() {
|
|
|
|
|
log!(Debug, lmode => " + {:?}", path);
|
|
|
|
|
done += args.mode.error_mode.handle(proc::do_dir(path.clone(), 0, &mut hashes, &args.mode)).log_and_forget(lmode, log::Level::Error)?.unwrap_or_default().unwrap_or_default();
|
|
|
|
|
log!(Info, lmode => " - {:?}", path);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log!(Info, lmode => "Found: {:?}", done);
|
|
|
|
|
log!(Debug, lmode => "New hashes: {:?}", hashes);
|
|
|
|
|
|
|
|
|
|
for save in args.save.iter()
|
|
|
|
|
{
|
|
|
|
|
let save = Path::new(save);
|
|
|
|
|
log!(Info, lmode => "Saving hashes to {:?}", save);
|
|
|
|
|
if let Some(mut file) = OpenOptions::new()
|
|
|
|
|
.create(true)
|
|
|
|
|
//.append(true)
|
|
|
|
|
.truncate(true)
|
|
|
|
|
.write(true)
|
|
|
|
|
.open(save).log_and_forget(lmode, log::Level::Warning)?
|
|
|
|
|
{
|
|
|
|
|
args.mode.error_mode.handle(hashes.save(&mut file)).log_and_forget(lmode, log::Level::Warning)?;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
log!(Fatal, log::Mode::Error => "{:?}", args);
|
|
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|