rust/hg-core/src/config/config.rs
changeset 46599 1f55cd5b292f
parent 46598 bc08c2331f99
child 46602 a687a7f27951
equal deleted inserted replaced
46598:bc08c2331f99 46599:1f55cd5b292f
   135         Ok(config)
   135         Ok(config)
   136     }
   136     }
   137 
   137 
   138     fn add_trusted_dir(&mut self, path: &Path) -> Result<(), ConfigError> {
   138     fn add_trusted_dir(&mut self, path: &Path) -> Result<(), ConfigError> {
   139         if let Some(entries) = std::fs::read_dir(path)
   139         if let Some(entries) = std::fs::read_dir(path)
   140             .for_file(path)
   140             .when_reading_file(path)
   141             .io_not_found_as_none()?
   141             .io_not_found_as_none()?
   142         {
   142         {
   143             for entry in entries {
   143             for entry in entries {
   144                 let file_path = entry.for_file(path)?.path();
   144                 let file_path = entry.when_reading_file(path)?.path();
   145                 if file_path.extension() == Some(std::ffi::OsStr::new("rc")) {
   145                 if file_path.extension() == Some(std::ffi::OsStr::new("rc")) {
   146                     self.add_trusted_file(&file_path)?
   146                     self.add_trusted_file(&file_path)?
   147                 }
   147                 }
   148             }
   148             }
   149         }
   149         }
   150         Ok(())
   150         Ok(())
   151     }
   151     }
   152 
   152 
   153     fn add_trusted_file(&mut self, path: &Path) -> Result<(), ConfigError> {
   153     fn add_trusted_file(&mut self, path: &Path) -> Result<(), ConfigError> {
   154         if let Some(data) =
   154         if let Some(data) = std::fs::read(path)
   155             std::fs::read(path).for_file(path).io_not_found_as_none()?
   155             .when_reading_file(path)
       
   156             .io_not_found_as_none()?
   156         {
   157         {
   157             self.layers.extend(ConfigLayer::parse(path, &data)?)
   158             self.layers.extend(ConfigLayer::parse(path, &data)?)
   158         }
   159         }
   159         Ok(())
   160         Ok(())
   160     }
   161     }