equal
deleted
inserted
replaced
1 use crate::errors::HgError; |
1 use crate::errors::{HgError, IoResultExt}; |
2 use crate::operations::{find_root, FindRootError}; |
2 use crate::operations::{find_root, FindRootError}; |
3 use crate::requirements; |
3 use crate::requirements; |
4 use memmap::{Mmap, MmapOptions}; |
4 use memmap::{Mmap, MmapOptions}; |
5 use std::path::{Path, PathBuf}; |
5 use std::path::{Path, PathBuf}; |
6 |
6 |
66 |
66 |
67 impl Vfs<'_> { |
67 impl Vfs<'_> { |
68 pub(crate) fn read( |
68 pub(crate) fn read( |
69 &self, |
69 &self, |
70 relative_path: impl AsRef<Path>, |
70 relative_path: impl AsRef<Path>, |
71 ) -> std::io::Result<Vec<u8>> { |
71 ) -> Result<Vec<u8>, HgError> { |
72 std::fs::read(self.base.join(relative_path)) |
72 let path = self.base.join(relative_path); |
73 } |
73 std::fs::read(&path).for_file(&path) |
74 |
|
75 pub(crate) fn open( |
|
76 &self, |
|
77 relative_path: impl AsRef<Path>, |
|
78 ) -> std::io::Result<std::fs::File> { |
|
79 std::fs::File::open(self.base.join(relative_path)) |
|
80 } |
74 } |
81 |
75 |
82 pub(crate) fn mmap_open( |
76 pub(crate) fn mmap_open( |
83 &self, |
77 &self, |
84 relative_path: impl AsRef<Path>, |
78 relative_path: impl AsRef<Path>, |
85 ) -> std::io::Result<Mmap> { |
79 ) -> Result<Mmap, HgError> { |
86 let file = self.open(relative_path)?; |
80 let path = self.base.join(relative_path); |
|
81 let file = std::fs::File::open(&path).for_file(&path)?; |
87 // TODO: what are the safety requirements here? |
82 // TODO: what are the safety requirements here? |
88 let mmap = unsafe { MmapOptions::new().map(&file) }?; |
83 let mmap = unsafe { MmapOptions::new().map(&file) }.for_file(&path)?; |
89 Ok(mmap) |
84 Ok(mmap) |
90 } |
85 } |
91 } |
86 } |