comparison rust/hg-core/src/config/layer.rs @ 46743:84a3deca963a

rhg: Silently ignore missing files in config %include … instead of aborting with an error message. This is what Python-based hg does. Differential Revision: https://phab.mercurial-scm.org/D10141
author Simon Sapin <simon.sapin@octobus.net>
date Mon, 08 Mar 2021 19:07:29 +0100
parents 91ab5190a3de
children 6e49769b7f97
comparison
equal deleted inserted replaced
46742:91ab5190a3de 46743:84a3deca963a
158 .parent() 158 .parent()
159 .expect("Path::parent fail on a file we’ve read"); 159 .expect("Path::parent fail on a file we’ve read");
160 // `Path::join` with an absolute argument correctly ignores the 160 // `Path::join` with an absolute argument correctly ignores the
161 // base path 161 // base path
162 let filename = dir.join(&get_path_from_bytes(&filename_bytes)); 162 let filename = dir.join(&get_path_from_bytes(&filename_bytes));
163 let data = std::fs::read(&filename).map_err(|io_error| { 163 match std::fs::read(&filename) {
164 ConfigParseError { 164 Ok(data) => {
165 origin: ConfigOrigin::File(src.to_owned()), 165 layers.push(current_layer);
166 line, 166 layers.extend(Self::parse(&filename, &data)?);
167 message: format_bytes!( 167 current_layer =
168 b"cannot include {} ({})", 168 Self::new(ConfigOrigin::File(src.to_owned()));
169 filename_bytes,
170 format_bytes::Utf8(io_error)
171 ),
172 } 169 }
173 })?; 170 Err(error) => {
174 layers.push(current_layer); 171 if error.kind() != std::io::ErrorKind::NotFound {
175 layers.extend(Self::parse(&filename, &data)?); 172 return Err(ConfigParseError {
176 current_layer = Self::new(ConfigOrigin::File(src.to_owned())); 173 origin: ConfigOrigin::File(src.to_owned()),
174 line,
175 message: format_bytes!(
176 b"cannot include {} ({})",
177 filename_bytes,
178 format_bytes::Utf8(error)
179 ),
180 }
181 .into());
182 }
183 }
184 }
177 } else if let Some(_) = EMPTY_RE.captures(&bytes) { 185 } else if let Some(_) = EMPTY_RE.captures(&bytes) {
178 } else if let Some(m) = SECTION_RE.captures(&bytes) { 186 } else if let Some(m) = SECTION_RE.captures(&bytes) {
179 section = m[1].to_vec(); 187 section = m[1].to_vec();
180 } else if let Some(m) = ITEM_RE.captures(&bytes) { 188 } else if let Some(m) = ITEM_RE.captures(&bytes) {
181 let item = m[1].to_vec(); 189 let item = m[1].to_vec();