(path: &Path)
| 209 | } |
| 210 | |
| 211 | fn read_json_object(path: &Path) -> AgentResult<Map<String, Value>> { |
| 212 | if !path.exists() { |
| 213 | return Ok(Map::new()); |
| 214 | } |
| 215 | let content = std::fs::read_to_string(path).map_err(|e| AgentError::ConfigError { |
| 216 | operation: "read".to_string(), |
| 217 | path: path.to_path_buf(), |
| 218 | reason: e.to_string(), |
| 219 | })?; |
| 220 | if content.trim().is_empty() { |
| 221 | return Ok(Map::new()); |
| 222 | } |
| 223 | let value: Value = serde_json::from_str(&content).map_err(|e| AgentError::ConfigError { |
| 224 | operation: "parse".to_string(), |
| 225 | path: path.to_path_buf(), |
| 226 | reason: e.to_string(), |
| 227 | })?; |
| 228 | match value { |
| 229 | Value::Object(map) => Ok(map), |
| 230 | _ => Ok(Map::new()), |
| 231 | } |
| 232 | } |
| 233 | |
| 234 | fn write_json_object(path: &Path, root: &Map<String, Value>) -> AgentResult<()> { |
| 235 | if let Some(parent) = path.parent() { |
no test coverage detected