| 149 | } |
| 150 | |
| 151 | fn normalize_path(path: &Path) -> Result<PathBuf, String> { |
| 152 | if path.is_absolute() { |
| 153 | Ok(path.to_path_buf()) |
| 154 | } else { |
| 155 | // check that no components of the path are '..' |
| 156 | if path.components().any(|c| c == std::path::Component::ParentDir) { |
| 157 | return Err(t!("resolve.invalidPath", path = path.to_string_lossy()).to_string()); |
| 158 | } |
| 159 | |
| 160 | // use DSC_CONFIG_ROOT env var as current directory |
| 161 | let current_directory = match std::env::var(DSC_CONFIG_ROOT) { |
| 162 | Ok(current_directory) => current_directory, |
| 163 | Err(_err) => { |
| 164 | // use current working directory |
| 165 | match std::env::current_dir() { |
| 166 | Ok(current_directory) => current_directory.to_string_lossy().into_owned(), |
| 167 | Err(err) => { |
| 168 | return Err(format!("{}: {err}", t!("resolve.failedGetCurrentDirectory"))); |
| 169 | } |
| 170 | } |
| 171 | } |
| 172 | }; |
| 173 | |
| 174 | // combine the current directory with the Include path |
| 175 | Ok(Path::new(¤t_directory).join(path)) |
| 176 | } |
| 177 | } |