equal
deleted
inserted
replaced
1 use memmap::Mmap; |
1 use memmap::Mmap; |
2 use std::convert::TryInto; |
2 use std::convert::TryInto; |
3 use std::path::{Path, PathBuf}; |
3 use std::path::{Path, PathBuf}; |
4 |
4 |
5 use super::revlog::{mmap_open, RevlogError}; |
5 use super::revlog::RevlogError; |
|
6 use crate::repo::Repo; |
6 use crate::utils::strip_suffix; |
7 use crate::utils::strip_suffix; |
7 |
8 |
8 const ONDISK_VERSION: u8 = 1; |
9 const ONDISK_VERSION: u8 = 1; |
9 |
10 |
10 pub(super) struct NodeMapDocket { |
11 pub(super) struct NodeMapDocket { |
21 /// * The docket has an unsupported version number (repositories created by |
22 /// * The docket has an unsupported version number (repositories created by |
22 /// later hg, maybe that should be a requirement instead?), or |
23 /// later hg, maybe that should be a requirement instead?), or |
23 /// * The docket file points to a missing (likely deleted) data file (this |
24 /// * The docket file points to a missing (likely deleted) data file (this |
24 /// can happen in a rare race condition). |
25 /// can happen in a rare race condition). |
25 pub fn read_from_file( |
26 pub fn read_from_file( |
|
27 repo: &Repo, |
26 index_path: &Path, |
28 index_path: &Path, |
27 ) -> Result<Option<(Self, Mmap)>, RevlogError> { |
29 ) -> Result<Option<(Self, Mmap)>, RevlogError> { |
28 let docket_path = index_path.with_extension("n"); |
30 let docket_path = index_path.with_extension("n"); |
29 let docket_bytes = match std::fs::read(&docket_path) { |
31 let docket_bytes = match repo.store_vfs().read(&docket_path) { |
30 Err(e) if e.kind() == std::io::ErrorKind::NotFound => { |
32 Err(e) if e.kind() == std::io::ErrorKind::NotFound => { |
31 return Ok(None) |
33 return Ok(None) |
32 } |
34 } |
33 Err(e) => return Err(RevlogError::IoError(e)), |
35 Err(e) => return Err(RevlogError::IoError(e)), |
34 Ok(bytes) => bytes, |
36 Ok(bytes) => bytes, |
58 let docket = NodeMapDocket { data_length }; |
60 let docket = NodeMapDocket { data_length }; |
59 |
61 |
60 let data_path = rawdata_path(&docket_path, uid); |
62 let data_path = rawdata_path(&docket_path, uid); |
61 // TODO: use `std::fs::read` here when the `persistent-nodemap.mmap` |
63 // TODO: use `std::fs::read` here when the `persistent-nodemap.mmap` |
62 // config is false? |
64 // config is false? |
63 match mmap_open(&data_path) { |
65 match repo.store_vfs().mmap_open(&data_path) { |
64 Ok(mmap) => { |
66 Ok(mmap) => { |
65 if mmap.len() >= data_length { |
67 if mmap.len() >= data_length { |
66 Ok(Some((docket, mmap))) |
68 Ok(Some((docket, mmap))) |
67 } else { |
69 } else { |
68 Err(RevlogError::Corrupted) |
70 Err(RevlogError::Corrupted) |