[yabridgectl] Rename utils module to util

This commit is contained in:
Robbert van der Helm
2022-05-23 12:57:11 +02:00
parent 1f35081bad
commit 6818b4fd09
6 changed files with 35 additions and 30 deletions
+21 -21
View File
@@ -27,8 +27,8 @@ use crate::config::{
yabridge_vst2_home, yabridge_vst3_home, Config, Vst2InstallationLocation, YabridgeFiles,
};
use crate::files::{self, NativeFile, Plugin, Vst2Plugin};
use crate::utils::{self, get_file_type};
use crate::utils::{verify_path_setup, verify_wine_setup};
use crate::util::{self, get_file_type};
use crate::util::{verify_path_setup, verify_wine_setup};
use crate::vst3_moduleinfo::ModuleInfo;
pub mod blacklist;
@@ -65,7 +65,7 @@ pub fn remove_directory(config: &mut Config, path: &Path) -> Result<()> {
) {
Ok(Some(answer)) if answer == "YES" => {
for file in &orphan_files {
utils::remove_file(file.path())?;
util::remove_file(file.path())?;
}
println!("\nRemoved {} files", orphan_files.len());
@@ -242,9 +242,9 @@ pub struct SyncOptions {
/// `.so` files if the prune option is set.
pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
let files: YabridgeFiles = config.files()?;
let vst2_chainloader_hash = utils::hash_file(&files.vst2_chainloader)?;
let vst2_chainloader_hash = util::hash_file(&files.vst2_chainloader)?;
let vst3_chainloader_hash = match &files.vst3_chainloader {
Some((path, _)) => Some(utils::hash_file(path)?),
Some((path, _)) => Some(util::hash_file(path)?),
None => None,
};
@@ -317,7 +317,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
let target_windows_plugin_path =
vst2_plugin.centralized_windows_target();
let normalized_target_native_plugin_path =
utils::normalize_path(&target_native_plugin_path);
util::normalize_path(&target_native_plugin_path);
let mut is_new = known_centralized_vst2_files
.insert(target_native_plugin_path.clone());
@@ -326,7 +326,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
if !is_new {
eprintln!(
"{}",
utils::wrap(&format!(
util::wrap(&format!(
"{}: '{}' has already been provided by another Wine prefix or plugin directory, skipping it\n",
"WARNING".red(),
target_windows_plugin_path.display(),
@@ -340,7 +340,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
// `libyabridge-chainloader-vst2.so` to (a subdirectory of)
// `~/.vst/yabridge`, and then we'll symlink the Windows VST2 plugin
// `.dll` file right next to it
utils::create_dir_all(target_native_plugin_path.parent().unwrap())?;
util::create_dir_all(target_native_plugin_path.parent().unwrap())?;
if install_file(
options.force,
InstallationMethod::Copy,
@@ -362,7 +362,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
}
Vst2InstallationLocation::Inline => {
let target_path = vst2_plugin.inline_native_target();
let normalized_target_path = utils::normalize_path(&target_path);
let normalized_target_path = util::normalize_path(&target_path);
// Since we skip some files, we'll also keep track of how many new file we've
// actually set up
@@ -393,7 +393,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
let target_native_module_path = module.target_native_module_path(Some(&files));
let target_windows_module_path = module.target_windows_module_path();
let normalized_native_module_path =
utils::normalize_path(&target_native_module_path);
util::normalize_path(&target_native_module_path);
// 32-bit and 64-bit versions of the plugin can live inside of the same bundle),
// but it's not possible to use the exact same plugin from multiple Wine
@@ -404,7 +404,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
if managed_vst3_bundle_files.contains(&target_windows_module_path) {
eprintln!(
"{}",
utils::wrap(&format!(
util::wrap(&format!(
"{}: The {} version of '{}' has already been provided by another Wine \
prefix or plugin directory, skipping '{}'\n",
"WARNING".red(),
@@ -421,7 +421,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
// `libyabridge-chainloader-vst3.so` and the Windows VST3 plugin. The path to
// this native module will depend on whether `libyabridge-chainloader-vst3.so`
// is a 32-bit or a 64-bit library file.
utils::create_dir_all(target_native_module_path.parent().unwrap())?;
util::create_dir_all(target_native_module_path.parent().unwrap())?;
if install_file(
options.force,
InstallationMethod::Copy,
@@ -440,7 +440,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
// We'll then symlink the Windows VST3 module to that bundle to create a merged
// bundle: https://developer.steinberg.help/display/VST/Plug-in+Format+Structure#PluginFormatStructure-MergedBundle
utils::create_dir_all(target_windows_module_path.parent().unwrap())?;
util::create_dir_all(target_windows_module_path.parent().unwrap())?;
install_file(
true,
InstallationMethod::Symlink,
@@ -479,7 +479,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
if let Some(original_moduleinfo_path) = module.original_moduleinfo_path() {
let target_moduleinfo_path = module.target_moduleinfo_path();
let result = utils::read_to_string(&original_moduleinfo_path)
let result = util::read_to_string(&original_moduleinfo_path)
.and_then(|module_info_json| {
serde_jsonrc::from_str(&module_info_json)
.context("Could not parse JSON file")
@@ -492,7 +492,7 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
let converted_json =
serde_jsonrc::to_string_pretty(&converted_module_info)
.context("Could not format JSON file")?;
utils::write(target_moduleinfo_path, converted_json)
util::write(target_moduleinfo_path, converted_json)
});
if let Err(error) = result {
eprintln!(
@@ -638,10 +638,10 @@ pub fn do_sync(config: &mut Config, options: &SyncOptions) -> Result<()> {
if options.prune {
match &file {
NativeFile::Regular(path) | NativeFile::Symlink(path) => {
utils::remove_file(path)?;
util::remove_file(path)?;
}
NativeFile::Directory(path) => {
utils::remove_dir_all(path)?;
util::remove_dir_all(path)?;
}
}
@@ -713,7 +713,7 @@ fn install_file(
// same as that of the `from` file we're trying to copy there, then we don't have to
// do anything
if let Some(hash) = from_hash {
if metadata.file_type().is_file() && utils::hash_file(to)? == hash {
if metadata.file_type().is_file() && util::hash_file(to)? == hash {
return Ok(false);
}
}
@@ -728,15 +728,15 @@ fn install_file(
(true, _) => (),
}
utils::remove_file(&to)?;
util::remove_file(&to)?;
};
match method {
InstallationMethod::Copy => {
utils::copy_or_reflink(from, to)?;
util::copy_or_reflink(from, to)?;
}
InstallationMethod::Symlink => {
utils::symlink(from, to)?;
util::symlink(from, to)?;
}
}
+3 -3
View File
@@ -27,7 +27,7 @@ use which::which;
use xdg::BaseDirectories;
use crate::files::{self, LibArchitecture, SearchResults};
use crate::utils;
use crate::util;
/// The name of the config file, relative to `$XDG_CONFIG_HOME/YABRIDGECTL_PREFIX`.
pub const CONFIG_FILE_NAME: &str = "config.toml";
@@ -250,7 +250,7 @@ impl Config {
// This is displayed in `yabridgectl status`
let vst2_chainloader_arch =
utils::get_elf_architecture(&vst2_chainloader).with_context(|| {
util::get_elf_architecture(&vst2_chainloader).with_context(|| {
format!(
"Could not determine ELF architecture for '{}'",
vst2_chainloader.display()
@@ -263,7 +263,7 @@ impl Config {
path if path.exists() => {
// We need to know `libyabridge-chainloader-vst3.so`'s architecture to be able to
// set up the bundle properly. 32-bit builds of yabridge are technically supported.
let arch = utils::get_elf_architecture(&path).with_context(|| {
let arch = util::get_elf_architecture(&path).with_context(|| {
format!(
"Could not determine ELF architecture for '{}'",
path.display()
+1 -1
View File
@@ -25,7 +25,7 @@ use walkdir::WalkDir;
use crate::config::{yabridge_vst2_home, yabridge_vst3_home, Config, YabridgeFiles};
use crate::symbols::parse_pe32_binary;
use crate::utils::get_file_type;
use crate::util::get_file_type;
/// Stores the results from searching through a directory. We'll search for Windows VST2 plugin
/// `.dll` files, Windows VST3 plugin modules, and native Linux `.so` files inside of a directory.
+2 -2
View File
@@ -27,7 +27,7 @@ mod actions;
mod config;
mod files;
mod symbols;
mod utils;
mod util;
mod vst3_moduleinfo;
fn main() -> Result<()> {
@@ -340,7 +340,7 @@ fn match_in_path_list<'a>(path: &Path, candidates: &'a HashSet<&Path>) -> Result
// This will include a trailing slash if `path` was `.`. All paths entered through yabridgectl
// will be cannonicalized and won't contain a trailing slash, but we'll try both variants
// anyways just in case someone edited the config file.
let normalized_path = utils::normalize_path(absolute_path.as_path());
let normalized_path = util::normalize_path(absolute_path.as_path());
// Is there a nicer way to strip trailing slashes with the standard library?
let normalized_path_str = normalized_path
+2 -2
View File
@@ -18,7 +18,7 @@ use anyhow::{anyhow, bail, Context, Result};
use std::io::BufRead;
use std::{path::Path, process::Command};
use crate::utils;
use crate::util;
/// Some information parsed from a PE32(+) binary. This is needed for setting up yabridge for
/// Windows plugin libraries.
@@ -45,7 +45,7 @@ pub fn parse_pe32_binary<P: AsRef<Path>>(binary: P) -> Result<Pe32Info> {
fn parse_pe32_goblin<P: AsRef<Path>>(binary: P) -> Result<Pe32Info> {
// The original version of this function also supports ELF and Mach architectures, but we don't
// need those things here
let bytes = utils::read(&binary)?;
let bytes = util::read(&binary)?;
let obj = goblin::pe::PE::parse(&bytes).with_context(|| {
format!(
"Could not parse '{}' as a PE32(+) binary",
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//! Small helper utilities.
//! Helper utilities and wrappers around filesystem functions for use with anyhow.
use anyhow::{anyhow, Context, Result};
use colored::Colorize;
@@ -61,6 +61,11 @@ pub fn create_dir_all<P: AsRef<Path>>(path: P) -> Result<()> {
})
}
/// Wrapper around [`std::fs::read()`](std::fs::read) with a human readable error message.
pub fn read<P: AsRef<Path>>(path: P) -> Result<Vec<u8>> {
fs::read(&path).with_context(|| format!("Could not read file '{}'", path.as_ref().display()))
}
/// Wrapper around [`std::fs::read_to_string()`](std::fs::read_to_string) with a human readable
/// error message.
pub fn read_to_string<P: AsRef<Path>>(path: P) -> Result<String> {