Open or create an identity store at the specified path.
(root: &Path)
| 391 | |
| 392 | /// Open or create an identity store at the specified path. |
| 393 | pub fn open(root: &Path) -> Result<Self, IdentityError> { |
| 394 | // Create the directory if it doesn't exist |
| 395 | if !root.exists() { |
| 396 | fs::create_dir_all(root)?; |
| 397 | } |
| 398 | |
| 399 | // Load or create configuration |
| 400 | let config_path = root.join(Self::CONFIG_FILE); |
| 401 | let config = if config_path.exists() { |
| 402 | let content = fs::read_to_string(&config_path)?; |
| 403 | toml::from_str(&content)? |
| 404 | } else { |
| 405 | let config = StoreConfig::new(); |
| 406 | let content = toml::to_string_pretty(&config)?; |
| 407 | fs::write(&config_path, content)?; |
| 408 | config |
| 409 | }; |
| 410 | |
| 411 | Ok(Self { |
| 412 | root: root.to_path_buf(), |
| 413 | config, |
| 414 | }) |
| 415 | } |
| 416 | |
| 417 | /// Get the default store path. |
| 418 | /// |
no test coverage detected