[yabridgectl] Consider subdirectories for orphans

This commit is contained in:
Robbert van der Helm
2021-01-03 22:43:57 +01:00
parent baf709d82e
commit 439c22c767
+22 -18
View File
@@ -21,6 +21,7 @@ use colored::Colorize;
use std::collections::{BTreeMap, BTreeSet}; use std::collections::{BTreeMap, BTreeSet};
use std::fs; use std::fs;
use std::path::{Path, PathBuf}; use std::path::{Path, PathBuf};
use walkdir::WalkDir;
use crate::config::{yabridge_vst3_home, Config, InstallationMethod, YabridgeFiles}; use crate::config::{yabridge_vst3_home, Config, InstallationMethod, YabridgeFiles};
use crate::files::{self, LibArchitecture, NativeFile}; use crate::files::{self, LibArchitecture, NativeFile};
@@ -327,24 +328,27 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
println!(); println!();
} }
if let Ok(dirs) = fs::read_dir(yabridge_vst3_home()) { // TODO: Move this elsewhere
orphan_files.extend( orphan_files.extend(
dirs.filter_map(|entry| entry.ok()) WalkDir::new(yabridge_vst3_home())
.map(|entry| entry.path()) .follow_links(true)
.filter_map(|path| { .same_file_system(true)
// Add all directories in `~/.vst3/yabridge` to `orphan_files` if they are not a .into_iter()
// VST3 module we just created. We'll ignore symlinks and regular files since .filter_entry(|entry| entry.file_type().is_dir())
// those are always user created. .filter_map(|e| e.ok())
match ( .filter(|entry| {
yabridge_vst3_bundles.contains_key(&path), // Add all directories in `~/.vst3/yabridge` to `orphan_files` if they are not a
utils::get_file_type(path), // VST3 module we just created. We'll ignore symlinks and regular files since those
) { // are always user created.
(false, result @ Some(NativeFile::Directory(_))) => result, let extension = entry
_ => None, .path()
} .extension()
}), .and_then(|extension| extension.to_str());
);
} extension == Some("vst3") && !yabridge_vst3_bundles.contains_key(entry.path())
})
.map(|entry| NativeFile::Directory(entry.path().to_owned())),
);
// Always warn about leftover files since those might cause warnings or errors when a VST host // Always warn about leftover files since those might cause warnings or errors when a VST host
// tries to load them // tries to load them