MCPcopy Create free account
hub / github.com/PowerShell/DSC / normalize_path

Function normalize_path

dsc/src/resolve.rs:151–177  ·  view source on GitHub ↗
(path: &Path)

Source from the content-addressed store, hash-verified

149}
150
151fn 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(&current_directory).join(path))
176 }
177}

Callers 1

get_contentsFunction · 0.85

Calls 1

newFunction · 0.50

Tested by

no test coverage detected