Open or create an identity store at the specified path.
(root: &Path)
| 375 | |
| 376 | /// Open or create an identity store at the specified path. |
| 377 | pub fn open(root: &Path) -> Result<Self, IdentityError> { |
| 378 | // Create the directory if it doesn't exist |
| 379 | if !root.exists() { |
| 380 | fs::create_dir_all(root)?; |
| 381 | } |
| 382 | |
| 383 | // Load or create configuration |
| 384 | let config_path = root.join(Self::CONFIG_FILE); |
| 385 | let config = if config_path.exists() { |
| 386 | let content = fs::read_to_string(&config_path)?; |
| 387 | toml::from_str(&content)? |
| 388 | } else { |
| 389 | let config = StoreConfig::new(); |
| 390 | let content = toml::to_string_pretty(&config)?; |
| 391 | fs::write(&config_path, content)?; |
| 392 | config |
| 393 | }; |
| 394 | |
| 395 | Ok(Self { |
| 396 | root: root.to_path_buf(), |
| 397 | config, |
| 398 | }) |
| 399 | } |
| 400 | |
| 401 | /// Get the default store path. |
| 402 | /// |
no test coverage detected