Mercurial > public > mercurial-scm > hg-stable
comparison rust/hg-core/src/repo.rs @ 46511:43d63979a75e
rust: use HgError in RevlogError and Vfs
Differential Revision: https://phab.mercurial-scm.org/D9897
author | Simon Sapin <simon.sapin@octobus.net> |
---|---|
date | Wed, 27 Jan 2021 14:45:25 +0100 |
parents | 02d3bb972121 |
children | 1dcd9c9975ed |
comparison
equal
deleted
inserted
replaced
46510:02d3bb972121 | 46511:43d63979a75e |
---|---|
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 } |