diff rust/hg-core/src/revlog/nodemap_docket.rs @ 46167:8a4914397d02

rust: introduce Repo and Vfs types for filesystem abstraction This is similar to the corresponding Python classes. Repo represents a repository and knows the path to the `.hg` directory, the `store` directory, and the working directory. Separating these will enable supporting the share extension. A Vfs is created from a Repo for one of these three directories. It has filesystem access APIs that take a relative std::path::Path as a parameter. Differential Revision: https://phab.mercurial-scm.org/D9596
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 14 Dec 2020 16:33:15 +0100
parents 9eb07ab3f2d4
children 0800aa42bb4c
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/nodemap_docket.rs	Sat Dec 19 15:56:54 2020 +0100
+++ b/rust/hg-core/src/revlog/nodemap_docket.rs	Mon Dec 14 16:33:15 2020 +0100
@@ -2,7 +2,8 @@
 use std::convert::TryInto;
 use std::path::{Path, PathBuf};
 
-use super::revlog::{mmap_open, RevlogError};
+use super::revlog::RevlogError;
+use crate::repo::Repo;
 use crate::utils::strip_suffix;
 
 const ONDISK_VERSION: u8 = 1;
@@ -23,10 +24,11 @@
     /// * The docket file points to a missing (likely deleted) data file (this
     ///   can happen in a rare race condition).
     pub fn read_from_file(
+        repo: &Repo,
         index_path: &Path,
     ) -> Result<Option<(Self, Mmap)>, RevlogError> {
         let docket_path = index_path.with_extension("n");
-        let docket_bytes = match std::fs::read(&docket_path) {
+        let docket_bytes = match repo.store_vfs().read(&docket_path) {
             Err(e) if e.kind() == std::io::ErrorKind::NotFound => {
                 return Ok(None)
             }
@@ -60,7 +62,7 @@
         let data_path = rawdata_path(&docket_path, uid);
         // TODO: use `std::fs::read` here when the `persistent-nodemap.mmap`
         // config is false?
-        match mmap_open(&data_path) {
+        match repo.store_vfs().mmap_open(&data_path) {
             Ok(mmap) => {
                 if mmap.len() >= data_length {
                     Ok(Some((docket, mmap)))