}
pub fn get_nth_entries(&self, count: usize) -> Result<Vec<Entry>, Error> {
let xdg_dirs = xdg::BaseDirectories::with_prefix("histdb-rs").unwrap();
let datadir_path = xdg_dirs.get_data_home();
let glob_string = datadir_path.join("*").join("*").join("*").join("*.csv");
let glob = glob::glob(&glob_string.to_string_lossy()).map_err(Error::InvalidGlob)?;
let index_paths = glob
.collect::<Result<Vec<PathBuf>, glob::GlobError>>()
.map_err(Error::GlobIteration)?;
let mut entries: Vec<_> = index_paths
.into_iter()
.map(Self::read_metadata_file)
.collect::<Result<Vec<Vec<_>>, Error>>()?
.into_iter()
.flatten()
.collect();
entries.sort();
let entries = entries.into_iter().rev().take(count).collect();
Ok(entries)
}
fn read_metadata_file<P: AsRef<Path>>(file_path: P) -> Result<Vec<Entry>, Error> {
let file = std::fs::File::open(&file_path)
.map_err(|err| Error::OpenLogFile(file_path.as_ref().to_path_buf(), err))?;
let reader = std::io::BufReader::new(file);
Self::read_metadata(reader)
.map_err(|err| Error::ReadLogFile(file_path.as_ref().to_path_buf(), err))