Main issue is probably when copying the content to the file, not during the file creation, but handle both cases just to be sure

This commit is contained in:
Laurent Louf 2020-08-04 12:25:32 +02:00
parent 9d832baf83
commit 5f11ddea50

View file

@ -85,21 +85,23 @@ impl 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 file_create = File::create(path); let mut cache_file = File::create(path).unwrap_or_else(|_e| {
match file_create { ::std::fs::remove_dir_all(&self.root.join("files")).unwrap();
Ok(mut cache_file) => { mkdir_existing(&self.root.join("files")).unwrap();
::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 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).unwrap(); File::create(path).unwrap()
::std::io::copy(contents, &mut cache_file).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()
});
} }
} }
} }