Print skipped files on yabridgectl sync -v

This commit is contained in:
Robbert van der Helm
2020-07-15 14:03:50 +02:00
parent 53ebfcd463
commit f9deb8c201
2 changed files with 35 additions and 25 deletions
+19 -19
View File
@@ -31,9 +31,9 @@ use walkdir::WalkDir;
pub struct SearchResults { pub struct SearchResults {
/// Absolute paths to the found VST2 `.dll` files. /// Absolute paths to the found VST2 `.dll` files.
pub vst2_files: Vec<PathBuf>, pub vst2_files: Vec<PathBuf>,
/// The number of skipped `.dll` files. Only used for printing statistics, so we don't keep /// `.dll` files skipped over during the serach. Used for printing statistics and shown when
/// track of the exact files. /// running `yabridgectl sync --verbose`.
pub num_skipped_files: usize, pub skipped_files: Vec<PathBuf>,
/// Absolute paths to any `.so` files inside of the directory, and whether they're a symlink or /// Absolute paths to any `.so` files inside of the directory, and whether they're a symlink or
/// a regular file. /// a regular file.
pub so_files: Vec<FoundFile>, pub so_files: Vec<FoundFile>,
@@ -122,15 +122,15 @@ pub fn index(directory: &Path) -> Result<SearchResults, std::io::Error> {
} }
} }
// Then we'll filter out any .dll files that are not VST2 plugins by checking whether the
// exptected entry points for VST2 plugins are present
lazy_static! { lazy_static! {
static ref VST2_AUTOMATON: AhoCorasick = static ref VST2_AUTOMATON: AhoCorasick =
AhoCorasick::new_auto_configured(&["VSTPluginMain", "main", "main_plugin"]); AhoCorasick::new_auto_configured(&["VSTPluginMain", "main", "main_plugin"]);
} }
let dll_file_count = dll_files.len(); // THne we'll figure out which `.dll` files are VST2 plugins and which should be skipped by
let vst2_files: Vec<PathBuf> = dll_files // checking whether the file contains one of the VST2 entry point functions. The boolean flag in
// this vector indicates whether it is a VST2 plugin.
let dll_files: Vec<(PathBuf, bool)> = dll_files
.into_par_iter() .into_par_iter()
.map(|path| { .map(|path| {
let exported_functions = Command::new("winedump") let exported_functions = Command::new("winedump")
@@ -140,23 +140,23 @@ pub fn index(directory: &Path) -> Result<SearchResults, std::io::Error> {
.output()? .output()?
.stdout; .stdout;
Ok((path, exported_functions)) Ok((path, VST2_AUTOMATON.is_match(exported_functions)))
})
.filter_map(|result| match result {
Ok((path, exported_functions)) => {
if VST2_AUTOMATON.is_match(exported_functions) {
Some(Ok(path))
} else {
None
}
}
Err(err) => Some(Err(err)),
}) })
.collect::<Result<_, std::io::Error>>()?; .collect::<Result<_, std::io::Error>>()?;
let mut vst2_files = Vec::new();
let mut skipped_files = Vec::new();
for (path, is_vst2_plugin) in dll_files {
if is_vst2_plugin {
vst2_files.push(path);
} else {
skipped_files.push(path);
}
}
Ok(SearchResults { Ok(SearchResults {
num_skipped_files: dll_file_count - vst2_files.len(),
vst2_files, vst2_files,
skipped_files,
so_files, so_files,
}) })
} }
+16 -6
View File
@@ -32,8 +32,6 @@ mod files;
// TODO: When creating copies, check whether `yabridge-host.exe` is in the PATH for the login shell // TODO: When creating copies, check whether `yabridge-host.exe` is in the PATH for the login shell
// TODO: Check for left over files when removing directory // TODO: Check for left over files when removing directory
// TODO: Reward parts of the readme // TODO: Reward parts of the readme
// TODO: Record .dll files processed, .dll files skipped and orphan .so files. Print a summary of
// the work done, and allow a --verbose option to print everything.
fn main() { fn main() {
let mut config = match Config::read() { let mut config = match Config::read() {
@@ -204,12 +202,12 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) {
// Keep track of some global statistics // Keep track of some global statistics
let mut num_installed = 0; let mut num_installed = 0;
let mut num_skipped = 0; let mut skipped_dll_files: Vec<PathBuf> = Vec::new();
let mut orphan_so_files: Vec<FoundFile> = Vec::new(); let mut orphan_so_files: Vec<FoundFile> = Vec::new();
for (path, search_results) in results { for (path, search_results) in results {
orphan_so_files.extend(search_results.orphans().into_iter().cloned());
num_installed += search_results.vst2_files.len(); num_installed += search_results.vst2_files.len();
num_skipped += search_results.num_skipped_files; orphan_so_files.extend(search_results.orphans().into_iter().cloned());
skipped_dll_files.extend(search_results.skipped_files);
if verbose { if verbose {
println!("{}:", path.display()); println!("{}:", path.display());
@@ -259,6 +257,18 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) {
} }
} }
// We'll print the skipped files all at once to prevetn clutter
let num_skipped_files = skipped_dll_files.len();
if verbose && !skipped_dll_files.is_empty() {
println!("Skipped files:");
for path in skipped_dll_files {
println!("- {}", path.display());
}
println!();
}
// Always warn about leftover files sicne those might cause warnings or errors when a VST host
// tries to load them
if !orphan_so_files.is_empty() { if !orphan_so_files.is_empty() {
if prune { if prune {
println!("Removing {} leftover '.so' file(s):", orphan_so_files.len()); println!("Removing {} leftover '.so' file(s):", orphan_so_files.len());
@@ -286,7 +296,7 @@ fn do_sync(config: &Config, prune: bool, verbose: bool) {
println!( println!(
"Finished setting up {} plugins, skipped {} non-plugin '.dll' files.", "Finished setting up {} plugins, skipped {} non-plugin '.dll' files.",
num_installed, num_skipped num_installed, num_skipped_files
) )
} }