Instead of disabling audio cache, just clean the audio cache and start caching again from the current file

This commit is contained in:
Laurent Louf 2020-08-03 13:18:23 +02:00
parent f075a75aee
commit 9d832baf83

View file

@ -83,15 +83,22 @@ impl Cache {
pub fn save_file(&self, file: FileId, contents: &mut dyn Read) { pub fn save_file(&self, file: FileId, contents: &mut dyn Read) {
if self.use_audio_cache { if self.use_audio_cache {
let path = self.file_path(file); let path = self.file_path(file);
mkdir_existing(path.parent().unwrap()).unwrap(); mkdir_existing(path.parent().unwrap()).unwrap();
let mut cache_file = File::create(path) let file_create = File::create(path);
match cache_file { match file_create {
Ok(file) => ::std::io::copy(contents, &mut file).unwrap(), Ok(mut cache_file) => {
Err(error) => { ::std::io::copy(contents, &mut cache_file).unwrap();
self.use_audio_cache = false }
}, Err(_error) => {
::std::fs::remove_dir_all(&self.root.join("files")).unwrap();
mkdir_existing(&self.root.join("files")).unwrap();
let path = self.file_path(file);
mkdir_existing(path.parent().unwrap()).unwrap();
let mut cache_file = File::create(path).unwrap();
::std::io::copy(contents, &mut cache_file).unwrap();
}
}; };
} }
} }