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