Mercurial > public > mercurial-scm > hg
diff rust/hg-core/src/utils/files.rs @ 46187:95d6f31e88db
hg-core: add basic config module
The config module exposes a `Config` struct, unused for now.
It only reads the config file local to the repository, but handles all valid
patterns and includes/unsets.
It is structured in layers instead of erasing by reverse order of precedence,
allowing us to transparently know more about the config for debugging purposes,
and potentially other things I haven't thought about yet.
This change also introduces `format_bytes!` to `hg-core`.
Differential Revision: https://phab.mercurial-scm.org/D9408
author | Rapha?l Gom?s <rgomes@octobus.net> |
---|---|
date | Tue, 29 Dec 2020 10:53:45 +0100 |
parents | 1b3197047f5c |
children | 0d734c0ae1cf |
line wrap: on
line diff
--- a/rust/hg-core/src/utils/files.rs Mon Dec 14 12:08:56 2020 +0100 +++ b/rust/hg-core/src/utils/files.rs Tue Dec 29 10:53:45 2020 +0100 @@ -18,6 +18,7 @@ use same_file::is_same_file; use std::borrow::{Cow, ToOwned}; use std::fs::Metadata; +use std::io::Read; use std::iter::FusedIterator; use std::ops::Deref; use std::path::{Path, PathBuf}; @@ -308,6 +309,17 @@ } } +/// Reads a file in one big chunk instead of doing multiple reads +pub fn read_whole_file(filepath: &Path) -> std::io::Result<Vec<u8>> { + let mut file = std::fs::File::open(filepath)?; + let size = file.metadata()?.len(); + + let mut res = vec![0; size as usize]; + file.read_exact(&mut res)?; + + Ok(res) +} + #[cfg(test)] mod tests { use super::*;