diff rust/hg-core/src/revlog/file_io.rs @ 52311:8d35941689af

rust-vfs: support checkambig This was missing from the Rust code, which means worse caching. See https://wiki.mercurial-scm.org/ExactCacheValidationPlan. Explanations on what ambiguity means inline.
author Rapha?l Gom?s <rgomes@octobus.net>
date Thu, 10 Oct 2024 15:54:45 +0200
parents 7be39c5110c9
children 645d247d4c75
line wrap: on
line diff
--- a/rust/hg-core/src/revlog/file_io.rs	Tue Oct 08 16:10:30 2024 +0200
+++ b/rust/hg-core/src/revlog/file_io.rs	Thu Oct 10 15:54:45 2024 +0200
@@ -2,7 +2,6 @@
 
 use std::{
     cell::RefCell,
-    fs::File,
     io::{Read, Seek, SeekFrom, Write},
     path::{Path, PathBuf},
     sync::{Arc, Mutex},
@@ -10,7 +9,7 @@
 
 use crate::{
     errors::{HgError, IoResultExt},
-    vfs::Vfs,
+    vfs::{Vfs, VfsFile},
 };
 
 /// Wraps accessing arbitrary chunks of data within a file and reusing handles.
@@ -123,12 +122,12 @@
     }
 }
 
-/// Holds an open [`File`] and the related data. This can be used for reading
-/// and writing. Writes can be delayed to a buffer before touching the disk,
-/// if relevant (in the changelog case), but reads are transparent.
+/// Holds an open [`VfsFile`] and the related data. This can be used for
+/// reading and writing. Writes can be delayed to a buffer before touching
+/// the disk, if relevant (in the changelog case), but reads are transparent.
 pub struct FileHandle {
     /// The actual open file
-    pub file: File,
+    pub file: VfsFile,
     /// The VFS with which the file was opened
     vfs: Box<dyn Vfs>,
     /// Filename of the open file, relative to the repo root
@@ -171,7 +170,7 @@
         write: bool,
     ) -> Result<Self, HgError> {
         let file = if create {
-            vfs.create(filename.as_ref())?
+            vfs.create(filename.as_ref(), false)?
         } else if write {
             vfs.open(filename.as_ref())?
         } else {
@@ -193,7 +192,7 @@
         delayed_buffer: Arc<Mutex<DelayedBuffer>>,
     ) -> Result<Self, HgError> {
         let mut file = if create {
-            vfs.create(filename.as_ref())?
+            vfs.create(filename.as_ref(), false)?
         } else {
             vfs.open(filename.as_ref())?
         };
@@ -216,9 +215,9 @@
         })
     }
 
-    /// Wrap an existing [`File`]
+    /// Wrap an existing [`VfsFile`]
     pub fn from_file(
-        file: File,
+        file: VfsFile,
         vfs: Box<dyn Vfs>,
         filename: impl AsRef<Path>,
     ) -> Self {
@@ -230,9 +229,9 @@
         }
     }
 
-    /// Wrap an existing [`File`], but writes go to a [`DelayedBuffer`].
+    /// Wrap an existing [`VfsFile`], but writes go to a [`DelayedBuffer`].
     pub fn from_file_delayed(
-        mut file: File,
+        mut file: VfsFile,
         vfs: Box<dyn Vfs>,
         filename: impl AsRef<Path>,
         delayed_buffer: Arc<Mutex<DelayedBuffer>>,