Fixed infinite loop in index process after IO errors

This commit is contained in:
Antoine Gersant 2017-07-08 01:32:41 -07:00
parent 58a083aec1
commit c5db1f250f

View file

@ -156,26 +156,22 @@ impl<'conn> IndexBuilder<'conn> {
Ok(())
}
fn get_artwork(&self, dir: &Path) -> Option<String> {
if let Ok(dir_content) = fs::read_dir(dir) {
for file in dir_content {
if let Ok(file) = file {
fn get_artwork(&self, dir: &Path) -> Result<Option<String>> {
for file in fs::read_dir(dir)? {
let file = file?;
if let Some(name_string) = file.file_name().to_str() {
if self.album_art_pattern.is_match(name_string) {
return file.path().to_str().map(|p| p.to_owned());
return Ok(file.path().to_str().map(|p| p.to_owned()));
}
}
}
}
}
None
Ok(None)
}
fn populate_directory(&mut self, parent: Option<&Path>, path: &Path) -> Result<()> {
// Find artwork
let artwork = self.get_artwork(path);
let artwork = self.get_artwork(path).unwrap_or(None);
// Extract path and parent path
let parent_string = parent.and_then(|p| p.to_str()).map(|s| s.to_owned());
@ -200,11 +196,13 @@ impl<'conn> IndexBuilder<'conn> {
let mut sub_directories = Vec::new();
// Insert content
if let Ok(dir_content) = fs::read_dir(path) {
for file in dir_content {
for file in fs::read_dir(path)? {
let file_path = match file {
Ok(f) => f.path(),
_ => continue,
_ => {
println!("File read error within {}", path_string);
break;
},
};
if file_path.is_dir() {
@ -253,7 +251,6 @@ impl<'conn> IndexBuilder<'conn> {
}
}
}
}
// Insert directory
if inconsistent_directory_year {