| 234 | } |
| 235 | |
| 236 | fn process_include<F>(current_file: &Path, new_file_name: &str, mut read_new_file: F) -> Result<()> |
| 237 | where F: FnMut(&Path) -> Result<()> { |
| 238 | let parent_path = current_file.parent(); |
| 239 | if parent_path.is_none() { |
| 240 | bail!("Internal error: {:?} is not a valid file name", current_file); |
| 241 | } |
| 242 | let mut new_file = parent_path.unwrap().to_path_buf(); |
| 243 | new_file.push(new_file_name); |
| 244 | info!("...processing include: {}...", new_file_name); |
| 245 | let new_file = match crate::shim_filesystem::canonicalize_shim(new_file.as_path()) { |
| 246 | Ok(buf) => buf, |
| 247 | Err(msg) => bail!("-include: constructed file name '{}' causes error '{}'", |
| 248 | new_file.to_str().unwrap(), msg), |
| 249 | }; |
| 250 | |
| 251 | return read_new_file(new_file.as_path()); |
| 252 | } |
| 253 | |
| 254 | /// As the name says, TreeOrString is either a Tree (Element) or a String |
| 255 | /// It is used to share code during pattern matching |