From 1d66481aad74974dce68926409cabe24ae9d6942 Mon Sep 17 00:00:00 2001 From: Robbert van der Helm Date: Wed, 14 Apr 2021 17:51:43 +0200 Subject: [PATCH] [yabridgectl] Add a blacklist #88 This lets you skip single plugins and entire directories during the indexing process. --- tools/yabridgectl/src/actions.rs | 4 ++-- tools/yabridgectl/src/config.rs | 12 ++++++++++-- tools/yabridgectl/src/files.rs | 9 ++++++--- 3 files changed, 18 insertions(+), 7 deletions(-) diff --git a/tools/yabridgectl/src/actions.rs b/tools/yabridgectl/src/actions.rs index e47a1b41..f9af093e 100644 --- a/tools/yabridgectl/src/actions.rs +++ b/tools/yabridgectl/src/actions.rs @@ -18,7 +18,7 @@ use anyhow::{Context, Result}; use colored::Colorize; -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::fs; use std::path::{Path, PathBuf}; use walkdir::WalkDir; @@ -43,7 +43,7 @@ pub fn remove_directory(config: &mut Config, path: &Path) -> Result<()> { // Ask the user to remove any leftover files to prevent possible future problems and out of date // copies - let orphan_files = files::index(path).so_files; + let orphan_files = files::index(path, &HashSet::new()).so_files; if !orphan_files.is_empty() { println!( "Warning: Found {} leftover .so files still in this directory:", diff --git a/tools/yabridgectl/src/config.rs b/tools/yabridgectl/src/config.rs index c1c89cfc..6e05e347 100644 --- a/tools/yabridgectl/src/config.rs +++ b/tools/yabridgectl/src/config.rs @@ -19,7 +19,7 @@ use anyhow::{anyhow, Context, Result}; use rayon::prelude::*; use serde_derive::{Deserialize, Serialize}; -use std::collections::{BTreeMap, BTreeSet}; +use std::collections::{BTreeMap, BTreeSet, HashSet}; use std::env; use std::fmt::Display; use std::fs; @@ -70,6 +70,11 @@ pub struct Config { /// Always skip post-installation setup checks. This can be set temporarily by passing the /// `--no-verify` option to `yabridgectl sync`. pub no_verify: bool, + /// Files and directories that should be skipped during the indexing process. If this contains a + /// directory, then everything under that directory will also be skipped. Like with + /// `plugin_dirs`, we're using a `BTreeSet` here because it looks nicer in the config file, even + /// though a hash set would make much more sense. + pub blacklist: BTreeSet, /// The last known combination of Wine and yabridge versions that would work together properly. /// This is mostly to diagnose issues with older Wine versions (such as those in Ubuntu's repos) /// early on. @@ -155,6 +160,7 @@ impl Default for Config { yabridge_home: None, plugin_dirs: BTreeSet::new(), no_verify: false, + blacklist: BTreeSet::new(), last_known_config: None, } } @@ -282,10 +288,12 @@ impl Config { /// Search for VST2 and VST3 plugins in all of the registered plugins directories. This will /// return an error if `winedump` could not be called. pub fn search_directories(&self) -> Result> { + let blacklist: HashSet<&Path> = self.blacklist.iter().map(|p| p.as_path()).collect(); + self.plugin_dirs .par_iter() .map(|path| { - files::index(path) + files::index(path, &blacklist) .search() .map(|search_results| (path.as_path(), search_results)) }) diff --git a/tools/yabridgectl/src/files.rs b/tools/yabridgectl/src/files.rs index f99f70ea..8ebc48a4 100644 --- a/tools/yabridgectl/src/files.rs +++ b/tools/yabridgectl/src/files.rs @@ -20,7 +20,7 @@ use aho_corasick::AhoCorasick; use anyhow::{Context, Result}; use lazy_static::lazy_static; use rayon::prelude::*; -use std::collections::{BTreeMap, HashMap}; +use std::collections::{BTreeMap, HashMap, HashSet}; use std::fmt::Display; use std::path::{Path, PathBuf}; use std::process::Command; @@ -321,8 +321,10 @@ impl SearchResults { } /// Find all `.dll`, `.vst3` and `.so` files under a directory. These results can be filtered down -/// to actual VST2 plugins and VST3 modules using `search()`. -pub fn index(directory: &Path) -> SearchIndex { +/// to actual VST2 plugins and VST3 modules using `search()`. Any path found in the blacklist will +/// be pruned immediately, so this can be used to both not index individual files and to skip an +/// entire directory. +pub fn index(directory: &Path, blacklist: &HashSet<&Path>) -> SearchIndex { let mut dll_files: Vec = Vec::new(); let mut vst3_files: Vec = Vec::new(); let mut so_files: Vec = Vec::new(); @@ -331,6 +333,7 @@ pub fn index(directory: &Path) -> SearchIndex { for (file_idx, entry) in WalkDir::new(directory) .follow_links(true) .into_iter() + .filter_entry(|e| !blacklist.contains(e.path())) .filter_map(|e| e.ok()) .filter(|e| !e.file_type().is_dir()) .enumerate()