Applied rustfmt

This commit is contained in:
Antoine Gersant 2016-11-30 23:16:06 -08:00
parent 1099c0dcf1
commit 85f4492b92
5 changed files with 29 additions and 27 deletions

View file

@ -73,7 +73,7 @@ impl Config {
}; };
root.push(DEFAULT_CONFIG_FILE_NAME); root.push(DEFAULT_CONFIG_FILE_NAME);
root root
}, }
}; };
println!("Loading config from: {}", config_path.to_string_lossy()); println!("Loading config from: {}", config_path.to_string_lossy());

View file

@ -106,8 +106,9 @@ impl<'db> IndexBuilder<'db> {
artist, album) VALUES (?, ?, ?, ?, ?, ?)") artist, album) VALUES (?, ?, ?, ?, ?, ?)")
.unwrap(), .unwrap(),
insert_song: insert_song:
db.prepare("INSERT OR REPLACE INTO songs (path, parent, disc_number, track_number, title, year, \ db.prepare("INSERT OR REPLACE INTO songs (path, parent, disc_number, track_number, \
album_artist, artist, album, artwork) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)") title, year, album_artist, artist, album, artwork) VALUES (?, ?, ?, ?, \
?, ?, ?, ?, ?, ?)")
.unwrap(), .unwrap(),
} }
} }
@ -183,9 +184,7 @@ impl<'db> Drop for IndexBuilder<'db> {
} }
impl Index { impl Index {
pub fn new(vfs: Arc<Vfs>, pub fn new(vfs: Arc<Vfs>, config: &IndexConfig) -> Result<Index, PError> {
config: &IndexConfig)
-> Result<Index, PError> {
let mut path = try!(utils::get_cache_root()); let mut path = try!(utils::get_cache_root());
path.push(INDEX_FILE_NAME); path.push(INDEX_FILE_NAME);
@ -246,14 +245,14 @@ impl Index {
, disc_number INTEGER , disc_number INTEGER
, track_number INTEGER , track_number INTEGER
, title TEXT , title TEXT
, artist TEXT \
, \ , artist TEXT
album_artist TEXT , album_artist TEXT
, year INTEGER , year INTEGER
, album TEXT , album TEXT
, artwork TEXT \
, \ , artwork TEXT
UNIQUE(path) , UNIQUE(path)
); );
") ")
@ -530,8 +529,9 @@ impl Index {
let db = self.connect(); let db = self.connect();
let path_string = real_path.to_string_lossy(); let path_string = real_path.to_string_lossy();
let mut select = let mut select =
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, artist, album, \ db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, \
artwork FROM songs WHERE parent = ? ORDER BY path COLLATE NOCASE ASC") artist, album, artwork FROM songs WHERE parent = ? ORDER BY path \
COLLATE NOCASE ASC")
.unwrap(); .unwrap();
select.bind(1, &Value::String(path_string.deref().to_owned())).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() 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 real_path = try!(self.vfs.virtual_to_real(virtual_path));
let path_string = real_path.to_string_lossy().into_owned() + "%"; let path_string = real_path.to_string_lossy().into_owned() + "%";
let mut select = let mut select =
db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, artist, album, \ db.prepare("SELECT path, disc_number, track_number, title, year, album_artist, \
artwork FROM songs WHERE path LIKE ? ORDER BY path COLLATE NOCASE ASC") artist, album, artwork FROM songs WHERE path LIKE ? ORDER BY path \
COLLATE NOCASE ASC")
.unwrap(); .unwrap();
select.bind(1, &Value::String(path_string.deref().to_owned())).unwrap(); select.bind(1, &Value::String(path_string.deref().to_owned())).unwrap();
Ok(self.select_songs(&mut select)) Ok(self.select_songs(&mut select))

View file

@ -70,8 +70,7 @@ fn main() {
// Init index // Init index
println!("Starting up index"); println!("Starting up index");
let index = Arc::new(index::Index::new(vfs.clone(), &config.index) let index = Arc::new(index::Index::new(vfs.clone(), &config.index).unwrap());
.unwrap());
let index_ref = index.clone(); let index_ref = index.clone();
std::thread::spawn(move || index_ref.run()); std::thread::spawn(move || index_ref.run());

View file

@ -24,7 +24,7 @@ fn hash(path: &Path, dimension: u32) -> u64 {
pub fn get_thumbnail(real_path: &Path, max_dimension: u32) -> Result<PathBuf, PError> { 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); out_path.push(THUMBNAILS_PATH);
let mut dir_builder = DirBuilder::new(); let mut dir_builder = DirBuilder::new();

View file

@ -5,24 +5,24 @@ use std::fs;
use error::PError; use error::PError;
pub fn get_config_root() -> Result<PathBuf, 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"); root.push("Polaris");
return match fs::create_dir_all(&root) { return match fs::create_dir_all(&root) {
Ok(()) => Ok(root), Ok(()) => Ok(root),
Err(_) => Err(PError::CacheDirectoryError), Err(_) => Err(PError::CacheDirectoryError),
} };
} }
Err(PError::ConfigDirectoryError) Err(PError::ConfigDirectoryError)
} }
pub fn get_cache_root() -> Result<PathBuf, PError> { 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"); root.push("Polaris");
return match fs::create_dir_all(&root) { return match fs::create_dir_all(&root) {
Ok(()) => Ok(root), Ok(()) => Ok(root),
Err(_) => Err(PError::CacheDirectoryError), Err(_) => Err(PError::CacheDirectoryError),
} };
} }
Err(PError::CacheDirectoryError) Err(PError::CacheDirectoryError)
} }
@ -56,8 +56,10 @@ pub fn get_audio_format(path: &Path) -> Option<AudioFormat> {
#[test] #[test]
fn test_get_audio_format() { 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.jpg")),
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.flac")), Some(AudioFormat::FLAC)); None);
assert_eq!(get_audio_format(Path::new("animals/🐷/my🐖file.flac")),
Some(AudioFormat::FLAC));
} }
pub fn is_song(path: &Path) -> bool { pub fn is_song(path: &Path) -> bool {