Load the user's default identity from the identity store. Looks for `~/.atomic/identities/config.toml` to find the default identity, then loads its `identity.toml` for name/email/public key. Returns `None` if: - The identity store directory doesn't exist - No default identity is configured - The default identity's files can't be read
(override_dir: Option<&Path>)
| 413 | /// - No default identity is configured |
| 414 | /// - The default identity's files can't be read |
| 415 | fn load_default_user_identity(override_dir: Option<&Path>) -> Option<UserIdentityInfo> { |
| 416 | let identities_dir = match override_dir { |
| 417 | Some(dir) => dir.to_path_buf(), |
| 418 | None => default_identities_dir()?, |
| 419 | }; |
| 420 | |
| 421 | if !identities_dir.is_dir() { |
| 422 | return None; |
| 423 | } |
| 424 | |
| 425 | // Read config.toml to find the default identity |
| 426 | let config_path = identities_dir.join("config.toml"); |
| 427 | let config_content = std::fs::read_to_string(&config_path).ok()?; |
| 428 | |
| 429 | // Parse the config to find the default identity directory name |
| 430 | let default_id = extract_default_identity_from_config(&config_content)?; |
| 431 | |
| 432 | // Try to find the identity directory |
| 433 | // The store uses {name}-{usage}-{id_short} as directory names, |
| 434 | // but we can also match by the ID directly |
| 435 | load_identity_by_id(&identities_dir, &default_id) |
| 436 | .or_else(|| load_identity_by_scanning(&identities_dir, &default_id)) |
| 437 | } |
| 438 | |
| 439 | /// Get the default identities directory: `~/.atomic/identities/` |
| 440 | fn default_identities_dir() -> Option<PathBuf> { |
no test coverage detected