diff --git a/core/src/cache.rs b/core/src/cache.rs index 65d31ba0..194240ea 100644 --- a/core/src/cache.rs +++ b/core/src/cache.rs @@ -85,21 +85,23 @@ impl Cache { let path = self.file_path(file); mkdir_existing(path.parent().unwrap()).unwrap(); - let file_create = File::create(path); - match file_create { - Ok(mut cache_file) => { - ::std::io::copy(contents, &mut cache_file).unwrap(); - } - Err(_error) => { - ::std::fs::remove_dir_all(&self.root.join("files")).unwrap(); - mkdir_existing(&self.root.join("files")).unwrap(); + let mut cache_file = File::create(path).unwrap_or_else(|_e| { + ::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(); - } - }; + let path = self.file_path(file); + mkdir_existing(path.parent().unwrap()).unwrap(); + File::create(path).unwrap() + }); + ::std::io::copy(contents, &mut cache_file).unwrap_or_else(|_e| { + ::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 file = File::create(path).unwrap(); + ::std::io::copy(contents, &mut file).unwrap() + }); } } }