[yabridgectl] Add a blacklist #88

This lets you skip single plugins and entire directories during the
indexing process.
This commit is contained in:
Robbert van der Helm
2021-04-14 17:51:43 +02:00
parent 6746b2b924
commit 1d66481aad
3 changed files with 18 additions and 7 deletions
+2 -2
View File
@@ -18,7 +18,7 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use colored::Colorize; use colored::Colorize;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use walkdir::WalkDir; 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 // Ask the user to remove any leftover files to prevent possible future problems and out of date
// copies // copies
let orphan_files = files::index(path).so_files; let orphan_files = files::index(path, &HashSet::new()).so_files;
if !orphan_files.is_empty() { if !orphan_files.is_empty() {
println!( println!(
"Warning: Found {} leftover .so files still in this directory:", "Warning: Found {} leftover .so files still in this directory:",
+10 -2
View File
@@ -19,7 +19,7 @@
use anyhow::{anyhow, Context, Result}; use anyhow::{anyhow, Context, Result};
use rayon::prelude::*; use rayon::prelude::*;
use serde_derive::{Deserialize, Serialize}; use serde_derive::{Deserialize, Serialize};
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet, HashSet};
use std::env; use std::env;
use std::fmt::Display; use std::fmt::Display;
use std::fs; use std::fs;
@@ -70,6 +70,11 @@ pub struct Config {
/// Always skip post-installation setup checks. This can be set temporarily by passing the /// Always skip post-installation setup checks. This can be set temporarily by passing the
/// `--no-verify` option to `yabridgectl sync`. /// `--no-verify` option to `yabridgectl sync`.
pub no_verify: bool, 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<PathBuf>,
/// The last known combination of Wine and yabridge versions that would work together properly. /// 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) /// This is mostly to diagnose issues with older Wine versions (such as those in Ubuntu's repos)
/// early on. /// early on.
@@ -155,6 +160,7 @@ impl Default for Config {
yabridge_home: None, yabridge_home: None,
plugin_dirs: BTreeSet::new(), plugin_dirs: BTreeSet::new(),
no_verify: false, no_verify: false,
blacklist: BTreeSet::new(),
last_known_config: None, 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 /// Search for VST2 and VST3 plugins in all of the registered plugins directories. This will
/// return an error if `winedump` could not be called. /// return an error if `winedump` could not be called.
pub fn search_directories(&self) -> Result<BTreeMap<&Path, SearchResults>> { pub fn search_directories(&self) -> Result<BTreeMap<&Path, SearchResults>> {
let blacklist: HashSet<&Path> = self.blacklist.iter().map(|p| p.as_path()).collect();
self.plugin_dirs self.plugin_dirs
.par_iter() .par_iter()
.map(|path| { .map(|path| {
files::index(path) files::index(path, &blacklist)
.search() .search()
.map(|search_results| (path.as_path(), search_results)) .map(|search_results| (path.as_path(), search_results))
}) })
+6 -3
View File
@@ -20,7 +20,7 @@ use aho_corasick::AhoCorasick;
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use lazy_static::lazy_static; use lazy_static::lazy_static;
use rayon::prelude::*; use rayon::prelude::*;
use std::collections::{BTreeMap, HashMap}; use std::collections::{BTreeMap, HashMap, HashSet};
use std::fmt::Display; use std::fmt::Display;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use std::process::Command; 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 /// 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()`. /// to actual VST2 plugins and VST3 modules using `search()`. Any path found in the blacklist will
pub fn index(directory: &Path) -> SearchIndex { /// 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<PathBuf> = Vec::new(); let mut dll_files: Vec<PathBuf> = Vec::new();
let mut vst3_files: Vec<PathBuf> = Vec::new(); let mut vst3_files: Vec<PathBuf> = Vec::new();
let mut so_files: Vec<NativeFile> = Vec::new(); let mut so_files: Vec<NativeFile> = Vec::new();
@@ -331,6 +333,7 @@ pub fn index(directory: &Path) -> SearchIndex {
for (file_idx, entry) in WalkDir::new(directory) for (file_idx, entry) in WalkDir::new(directory)
.follow_links(true) .follow_links(true)
.into_iter() .into_iter()
.filter_entry(|e| !blacklist.contains(e.path()))
.filter_map(|e| e.ok()) .filter_map(|e| e.ok())
.filter(|e| !e.file_type().is_dir()) .filter(|e| !e.file_type().is_dir())
.enumerate() .enumerate()