mirror of
https://github.com/agersant/polaris
synced 2024-11-10 10:14:12 +00:00
Applied rustfmt
This commit is contained in:
parent
1099c0dcf1
commit
85f4492b92
5 changed files with 29 additions and 27 deletions
|
@ -73,7 +73,7 @@ impl Config {
|
|||
};
|
||||
root.push(DEFAULT_CONFIG_FILE_NAME);
|
||||
root
|
||||
},
|
||||
}
|
||||
};
|
||||
println!("Loading config from: {}", config_path.to_string_lossy());
|
||||
|
||||
|
|
31
src/index.rs
31
src/index.rs
|
@ -106,8 +106,9 @@ impl<'db> IndexBuilder<'db> {
|
|||
artist, album) VALUES (?, ?, ?, ?, ?, ?)")
|
||||
.unwrap(),
|
||||
insert_song:
|
||||
db.prepare("INSERT OR REPLACE INTO songs (path, parent, disc_number, track_number, title, year, \
|
||||
album_artist, artist, album, artwork) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)")
|
||||
db.prepare("INSERT OR REPLACE INTO songs (path, parent, disc_number, track_number, \
|
||||
title, year, album_artist, artist, album, artwork) VALUES (?, ?, ?, ?, \
|
||||
?, ?, ?, ?, ?, ?)")
|
||||
.unwrap(),
|
||||
}
|
||||
}
|
||||
|
@ -183,9 +184,7 @@ impl<'db> Drop for IndexBuilder<'db> {
|
|||
}
|
||||
|
||||
impl Index {
|
||||
pub fn new(vfs: Arc<Vfs>,
|
||||
config: &IndexConfig)
|
||||
-> Result<Index, PError> {
|
||||
pub fn new(vfs: Arc<Vfs>, config: &IndexConfig) -> Result<Index, PError> {
|
||||
|
||||
let mut path = try!(utils::get_cache_root());
|
||||
path.push(INDEX_FILE_NAME);
|
||||
|
@ -246,14 +245,14 @@ impl Index {
|
|||
, disc_number INTEGER
|
||||
, track_number INTEGER
|
||||
, title TEXT
|
||||
, artist TEXT
|
||||
, \
|
||||
album_artist TEXT
|
||||
\
|
||||
, artist TEXT
|
||||
, album_artist TEXT
|
||||
, year INTEGER
|
||||
, album TEXT
|
||||
, artwork TEXT
|
||||
, \
|
||||
UNIQUE(path)
|
||||
\
|
||||
, artwork TEXT
|
||||
, UNIQUE(path)
|
||||
);
|
||||
|
||||
")
|
||||
|
@ -530,8 +529,9 @@ impl Index {
|
|||
let db = self.connect();
|
||||
let path_string = real_path.to_string_lossy();
|
||||
let mut select =
|
||||
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, artist, album, \
|
||||
artwork FROM songs WHERE parent = ? ORDER BY path COLLATE NOCASE ASC")
|
||||
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, \
|
||||
artist, album, artwork FROM songs WHERE parent = ? ORDER BY path \
|
||||
COLLATE NOCASE ASC")
|
||||
.unwrap();
|
||||
select.bind(1, &Value::String(path_string.deref().to_owned())).unwrap();
|
||||
self.select_songs(&mut select).into_iter().map(|s| CollectionFile::Song(s)).collect()
|
||||
|
@ -571,8 +571,9 @@ impl Index {
|
|||
let real_path = try!(self.vfs.virtual_to_real(virtual_path));
|
||||
let path_string = real_path.to_string_lossy().into_owned() + "%";
|
||||
let mut select =
|
||||
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, artist, album, \
|
||||
artwork FROM songs WHERE path LIKE ? ORDER BY path COLLATE NOCASE ASC")
|
||||
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, \
|
||||
artist, album, artwork FROM songs WHERE path LIKE ? ORDER BY path \
|
||||
COLLATE NOCASE ASC")
|
||||
.unwrap();
|
||||
select.bind(1, &Value::String(path_string.deref().to_owned())).unwrap();
|
||||
Ok(self.select_songs(&mut select))
|
||||
|
|
|
@ -70,8 +70,7 @@ fn main() {
|
|||
|
||||
// Init index
|
||||
println!("Starting up index");
|
||||
let index = Arc::new(index::Index::new(vfs.clone(), &config.index)
|
||||
.unwrap());
|
||||
let index = Arc::new(index::Index::new(vfs.clone(), &config.index).unwrap());
|
||||
let index_ref = index.clone();
|
||||
std::thread::spawn(move || index_ref.run());
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ fn hash(path: &Path, dimension: u32) -> u64 {
|
|||
|
||||
pub fn get_thumbnail(real_path: &Path, max_dimension: u32) -> Result<PathBuf, PError> {
|
||||
|
||||
let mut out_path = try!(utils::get_cache_root());
|
||||
let mut out_path = try!(utils::get_cache_root());
|
||||
out_path.push(THUMBNAILS_PATH);
|
||||
|
||||
let mut dir_builder = DirBuilder::new();
|
||||
|
|
18
src/utils.rs
18
src/utils.rs
|
@ -5,24 +5,24 @@ use std::fs;
|
|||
use error::PError;
|
||||
|
||||
pub fn get_config_root() -> Result<PathBuf, PError> {
|
||||
if let Ok(mut root) = data_root(AppDataType::SharedConfig){
|
||||
if let Ok(mut root) = data_root(AppDataType::SharedConfig) {
|
||||
root.push("Polaris");
|
||||
return match fs::create_dir_all(&root) {
|
||||
Ok(()) => Ok(root),
|
||||
Err(_) => Err(PError::CacheDirectoryError),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(PError::ConfigDirectoryError)
|
||||
}
|
||||
|
||||
pub fn get_cache_root() -> Result<PathBuf, PError> {
|
||||
if let Ok(mut root) = data_root(AppDataType::SharedData){
|
||||
if let Ok(mut root) = data_root(AppDataType::SharedData) {
|
||||
root.push("Polaris");
|
||||
return match fs::create_dir_all(&root) {
|
||||
Ok(()) => Ok(root),
|
||||
Err(_) => Err(PError::CacheDirectoryError),
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
Err(PError::CacheDirectoryError)
|
||||
}
|
||||
|
||||
|
@ -56,8 +56,10 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
|
|||
|
||||
#[test]
|
||||
fn test_get_audio_format() {
|
||||
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")), None);
|
||||
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.flac")), Some(AudioFormat::FLAC));
|
||||
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.jpg")),
|
||||
None);
|
||||
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.flac")),
|
||||
Some(AudioFormat::FLAC));
|
||||
}
|
||||
|
||||
pub fn is_song(path: &Path) -> bool {
|
||||
|
|
Loading…
Reference in a new issue