()
| 119 | } |
| 120 | |
| 121 | fn get_resource_paths() -> Result<Vec<PathBuf>, DscError> |
| 122 | { |
| 123 | let mut resource_path_setting = ResourcePathSetting::default(); |
| 124 | |
| 125 | match Self::get_resource_path_setting() { |
| 126 | Ok(v) => { |
| 127 | resource_path_setting = v; |
| 128 | }, |
| 129 | Err(e) => { |
| 130 | debug!("{e}"); |
| 131 | } |
| 132 | } |
| 133 | |
| 134 | let mut using_custom_path = false; |
| 135 | let mut paths: Vec<PathBuf> = vec![]; |
| 136 | |
| 137 | let dsc_resource_path = env::var_os("DSC_RESOURCE_PATH"); |
| 138 | if resource_path_setting.allow_env_override && dsc_resource_path.is_some() { |
| 139 | if let Some(value) = dsc_resource_path { |
| 140 | debug!("DSC_RESOURCE_PATH: {:?}", value.to_string_lossy()); |
| 141 | using_custom_path = true; |
| 142 | paths.append(&mut env::split_paths(&value).collect::<Vec<_>>()); |
| 143 | } |
| 144 | } else { |
| 145 | for p in resource_path_setting.directories { |
| 146 | let v = PathBuf::from_str(&p); |
| 147 | paths.push(v.unwrap_or_default()); |
| 148 | } |
| 149 | |
| 150 | if resource_path_setting.append_env_path { |
| 151 | debug!("{}", t!("discovery.commandDiscovery.appendingEnvPath")); |
| 152 | match env::var_os("PATH") { |
| 153 | Some(value) => { |
| 154 | trace!("{}", t!("discovery.commandDiscovery.originalPath", path = value.to_string_lossy())); |
| 155 | paths.append(&mut env::split_paths(&value).collect::<Vec<_>>()); |
| 156 | }, |
| 157 | None => { |
| 158 | return Err(DscError::Operation(t!("discovery.commandDiscovery.failedGetEnvPath").to_string())); |
| 159 | } |
| 160 | } |
| 161 | } |
| 162 | } |
| 163 | |
| 164 | // remove duplicate entries |
| 165 | let mut uniques: HashSet<PathBuf> = HashSet::new(); |
| 166 | paths.retain(|e|uniques.insert((*e).clone())); |
| 167 | |
| 168 | if using_custom_path { |
| 169 | // when using custom path, intent is to isolate the search of manifests and executables to the custom path |
| 170 | // so we replace the PATH with the custom path |
| 171 | if let Ok(new_path) = env::join_paths(paths.clone()) { |
| 172 | unsafe { |
| 173 | env::set_var("PATH", new_path); |
| 174 | } |
| 175 | } else { |
| 176 | return Err(DscError::Operation(t!("discovery.commandDiscovery.failedJoinEnvPath").to_string())); |
| 177 | } |
| 178 | } else { |
nothing calls this directly
no test coverage detected