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