rust/hg-core/src/vfs.rs
changeset 49485 ffd4b1f1c9cb
parent 48418 abeae090ce67
child 49914 58074252db3c
child 50180 be019ac8c1e4
equal deleted inserted replaced
49484:85f5d11c77dd 49485:ffd4b1f1c9cb
    36         &self,
    36         &self,
    37         relative_path: impl AsRef<Path>,
    37         relative_path: impl AsRef<Path>,
    38     ) -> Result<Vec<u8>, HgError> {
    38     ) -> Result<Vec<u8>, HgError> {
    39         let path = self.join(relative_path);
    39         let path = self.join(relative_path);
    40         std::fs::read(&path).when_reading_file(&path)
    40         std::fs::read(&path).when_reading_file(&path)
       
    41     }
       
    42 
       
    43     /// Returns `Ok(None)` if the file does not exist.
       
    44     pub fn try_read(
       
    45         &self,
       
    46         relative_path: impl AsRef<Path>,
       
    47     ) -> Result<Option<Vec<u8>>, HgError> {
       
    48         match self.read(relative_path) {
       
    49             Err(e) => match &e {
       
    50                 HgError::IoError { error, .. } => match error.kind() {
       
    51                     ErrorKind::NotFound => return Ok(None),
       
    52                     _ => Err(e),
       
    53                 },
       
    54                 _ => Err(e),
       
    55             },
       
    56             Ok(v) => Ok(Some(v)),
       
    57         }
    41     }
    58     }
    42 
    59 
    43     fn mmap_open_gen(
    60     fn mmap_open_gen(
    44         &self,
    61         &self,
    45         relative_path: impl AsRef<Path>,
    62         relative_path: impl AsRef<Path>,