tsk-76: Cleanup
This commit is contained in:
@@ -68,26 +68,21 @@ impl CoverArt {
|
||||
/// Gets the path of the CoverArt
|
||||
pub fn get_path(&self) -> Result<String, std::io::Error> {
|
||||
if self.directory.is_empty() {
|
||||
return Err(std::io::Error::other("Directory has not been initialized"));
|
||||
return Err(std::io::Error::other(
|
||||
crate::constants::error::DIRECTORY_NOT_INITIALIZED,
|
||||
));
|
||||
} else if self.filename.is_empty() {
|
||||
return Err(std::io::Error::other("Filename has not bee initialized"));
|
||||
return Err(std::io::Error::other(
|
||||
crate::constants::error::FILENAME_NOT_INITIALIZED,
|
||||
));
|
||||
}
|
||||
|
||||
let directory = &self.directory;
|
||||
let last_index = directory.len() - 1;
|
||||
|
||||
if let Some(character) = directory.chars().nth(last_index) {
|
||||
let buffer = if character != '/' {
|
||||
directory.clone() + "/"
|
||||
} else {
|
||||
directory.clone()
|
||||
};
|
||||
|
||||
Ok(buffer + &self.filename.clone())
|
||||
} else {
|
||||
Err(std::io::Error::other(
|
||||
"Could not access last character of directory",
|
||||
))
|
||||
match crate::util::concatenate_path(&directory, &self.filename, last_index) {
|
||||
Ok(path) => Ok(path),
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
26
src/song.rs
26
src/song.rs
@@ -69,34 +69,24 @@ impl Song {
|
||||
}
|
||||
}
|
||||
|
||||
/// Gets the path of a Song
|
||||
pub fn song_path(&self) -> Result<String, std::io::Error> {
|
||||
if self.directory.is_empty() {
|
||||
return Err(std::io::Error::other(crate::constants::error::DIRECTORY_NOT_INITIALIZED));
|
||||
return Err(std::io::Error::other(
|
||||
crate::constants::error::DIRECTORY_NOT_INITIALIZED,
|
||||
));
|
||||
} else if self.filename.is_empty() {
|
||||
return Err(std::io::Error::other(crate::constants::error::FILENAME_NOT_INITIALIZED));
|
||||
return Err(std::io::Error::other(
|
||||
crate::constants::error::FILENAME_NOT_INITIALIZED,
|
||||
));
|
||||
}
|
||||
|
||||
let directory = &self.directory;
|
||||
let last_index = directory.len() - 1;
|
||||
|
||||
/*
|
||||
if let Some(character) = directory.chars().nth(last_index) {
|
||||
let buffer: String = if character != '/' {
|
||||
directory.clone() + "/"
|
||||
} else {
|
||||
directory.clone()
|
||||
};
|
||||
|
||||
Ok(buffer + &self.filename.clone())
|
||||
} else {
|
||||
Err(std::io::Error::other(
|
||||
"Could not access last character of directory",
|
||||
))
|
||||
}
|
||||
*/
|
||||
match crate::util::concatenate_path(&directory, &self.filename, last_index) {
|
||||
Ok(path) => Ok(path),
|
||||
Err(err) => Err(err)
|
||||
Err(err) => Err(err),
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
pub fn concatenate_path(directory: &str, filename: &str, last_index: usize) -> Result<String, std::io::Error> {
|
||||
pub fn concatenate_path(
|
||||
directory: &str,
|
||||
filename: &str,
|
||||
last_index: usize,
|
||||
) -> Result<String, std::io::Error> {
|
||||
if let Some(character) = directory.chars().nth(last_index) {
|
||||
let buffer: String = if character != '/' {
|
||||
format!("{directory}/")
|
||||
@@ -8,6 +12,8 @@ pub fn concatenate_path(directory: &str, filename: &str, last_index: usize) -> R
|
||||
|
||||
Ok(format!("{buffer}{filename}"))
|
||||
} else {
|
||||
Err(std::io::Error::other(crate::constants::error::LAST_CHARACTER_IN_DIRECTORY))
|
||||
Err(std::io::Error::other(
|
||||
crate::constants::error::LAST_CHARACTER_IN_DIRECTORY,
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user