Rename SystemExecutor to CommandExecutor

This commit is contained in:
Wojciech Kozlowski 2023-04-10 21:35:40 +02:00
parent 68d5fa69d4
commit a0d38454ca
4 changed files with 21 additions and 21 deletions

View File

@ -53,13 +53,13 @@ impl DatabaseWrite for JsonDatabase {
impl Database for JsonDatabase {} impl Database for JsonDatabase {}
/// JSON database that uses a local file for persistent storage. /// JSON database backend that uses a local file for persistent storage.
pub struct JsonDatabaseFileBackend { pub struct JsonDatabaseFileBackend {
path: PathBuf, path: PathBuf,
} }
impl JsonDatabaseFileBackend { impl JsonDatabaseFileBackend {
/// Create a database instance that will read/write to the provided path. /// Create a [JsonDatabaseFileBackend] that will read/write to the provided path.
pub fn new(path: &Path) -> Self { pub fn new(path: &Path) -> Self {
JsonDatabaseFileBackend { JsonDatabaseFileBackend {
path: path.to_path_buf(), path: path.to_path_buf(),

View File

@ -89,7 +89,7 @@ pub trait BeetsLibraryExecutor {
fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error>; fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error>;
} }
/// Struct for interacting with the music library via beets. /// Beets library.
pub struct BeetsLibrary { pub struct BeetsLibrary {
executor: Box<dyn BeetsLibraryExecutor + Send>, executor: Box<dyn BeetsLibraryExecutor + Send>,
} }
@ -106,7 +106,7 @@ trait LibraryPrivate {
} }
impl BeetsLibrary { impl BeetsLibrary {
/// Create a new beets library with the provided executor, e.g. [BeetsLibrarySystemExecutor]. /// Create a new beets library with the provided executor, e.g. [BeetsLibraryCommandExecutor].
pub fn new(executor: Box<dyn BeetsLibraryExecutor + Send>) -> BeetsLibrary { pub fn new(executor: Box<dyn BeetsLibraryExecutor + Send>) -> BeetsLibrary {
BeetsLibrary { executor } BeetsLibrary { executor }
} }
@ -236,42 +236,42 @@ impl LibraryPrivate for BeetsLibrary {
} }
} }
/// Executor for executing beets commands on the local system. /// Beets library executor that executes beets commands in their own process.
/// ///
/// # Safety /// # Safety
/// ///
/// The beets executable is not safe to call concurrently for operations on the same /// The beets executable is not safe to call concurrently for operations on the same
/// database/library. Therefore, all functions that create a [SystemExecutor] or modify which /// database/library. Therefore, all functions that create a [BeetsLibraryCommandExecutor] or modify
/// library it works with are marked unsafe. It is the caller's responsibility to make sure the /// which library it works with are marked unsafe. It is the caller's responsibility to make sure
/// library is not being concurrently accessed from anywhere else. /// the library is not being concurrently accessed from anywhere else.
pub struct BeetsLibrarySystemExecutor { pub struct BeetsLibraryCommandExecutor {
bin: String, bin: String,
config: Option<PathBuf>, config: Option<PathBuf>,
} }
impl BeetsLibrarySystemExecutor { impl BeetsLibraryCommandExecutor {
/// Create a new [SystemExecutor] that uses the provided beets executable. /// Create a new [BeetsLibraryCommandExecutor] that uses the provided beets executable.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller must ensure the library is not being concurrently accessed from anywhere else. /// The caller must ensure the library is not being concurrently accessed from anywhere else.
pub unsafe fn new(bin: &str) -> Self { pub unsafe fn new(bin: &str) -> Self {
BeetsLibrarySystemExecutor { BeetsLibraryCommandExecutor {
bin: bin.to_string(), bin: bin.to_string(),
config: None, config: None,
} }
} }
/// Create a new [SystemExecutor] that uses the system's default beets executable. /// Create a new [BeetsLibraryCommandExecutor] that uses the system's default beets executable.
/// ///
/// # Safety /// # Safety
/// ///
/// The caller must ensure the library is not being concurrently accessed from anywhere else. /// The caller must ensure the library is not being concurrently accessed from anywhere else.
pub unsafe fn default() -> Self { pub unsafe fn default() -> Self {
BeetsLibrarySystemExecutor::new("beet") BeetsLibraryCommandExecutor::new("beet")
} }
/// Update the configuration file for the beets executable. /// Update the configuration file passed to the beets executable.
/// ///
/// # Safety /// # Safety
/// ///
@ -282,7 +282,7 @@ impl BeetsLibrarySystemExecutor {
} }
} }
impl BeetsLibraryExecutor for BeetsLibrarySystemExecutor { impl BeetsLibraryExecutor for BeetsLibraryCommandExecutor {
fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error> { fn exec(&mut self, arguments: &[String]) -> Result<Vec<String>, Error> {
let mut cmd = Command::new(&self.bin); let mut cmd = Command::new(&self.bin);
if let Some(ref path) = self.config { if let Some(ref path) = self.config {

View File

@ -8,7 +8,7 @@ use musichoard::{
DatabaseWrite, DatabaseWrite,
}, },
library::{ library::{
beets::{BeetsLibrary, BeetsLibrarySystemExecutor}, beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
Library, Query, Library, Query,
}, },
}; };
@ -37,7 +37,7 @@ fn main() {
let opt = Opt::from_args(); let opt = Opt::from_args();
let mut beets = BeetsLibrary::new(Box::new(unsafe { let mut beets = BeetsLibrary::new(Box::new(unsafe {
BeetsLibrarySystemExecutor::default().config(opt.beets_config_file_path.as_deref()) BeetsLibraryCommandExecutor::default().config(opt.beets_config_file_path.as_deref())
})); }));
let collection = beets let collection = beets

View File

@ -7,7 +7,7 @@ use once_cell::sync::Lazy;
use musichoard::{ use musichoard::{
library::{ library::{
beets::{BeetsLibrary, BeetsLibrarySystemExecutor}, beets::{BeetsLibrary, BeetsLibraryCommandExecutor},
Library, Query, QueryOption, Library, Query, QueryOption,
}, },
Artist, Artist,
@ -17,13 +17,13 @@ use crate::COLLECTION;
static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| { static BEETS_EMPTY_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe { Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe {
BeetsLibrarySystemExecutor::default() BeetsLibraryCommandExecutor::default()
})))) }))))
}); });
static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| { static BEETS_TEST_CONFIG: Lazy<Arc<Mutex<BeetsLibrary>>> = Lazy::new(|| {
Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe { Arc::new(Mutex::new(BeetsLibrary::new(Box::new(unsafe {
BeetsLibrarySystemExecutor::default().config(Some( BeetsLibraryCommandExecutor::default().config(Some(
&fs::canonicalize("./tests/files/library/config.yml").unwrap(), &fs::canonicalize("./tests/files/library/config.yml").unwrap(),
)) ))
})))) }))))