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>)
| 230 | /// - No default identity is configured |
| 231 | /// - The default identity's files can't be read |
| 232 | fn load_default_user_identity(override_dir: Option<&Path>) -> Option<UserIdentityInfo> { |
| 233 | let identities_dir = match override_dir { |
| 234 | Some(dir) => dir.to_path_buf(), |
| 235 | None => default_identities_dir()?, |
| 236 | }; |
| 237 | |
| 238 | if !identities_dir.is_dir() { |
| 239 | return None; |
| 240 | } |
| 241 | |
| 242 | // Read config.toml to find the default identity |
| 243 | let config_path = identities_dir.join("config.toml"); |
| 244 | let config_content = std::fs::read_to_string(&config_path).ok()?; |
| 245 | |
| 246 | // Parse the config to find the default identity directory name |
| 247 | let default_id = extract_default_identity_from_config(&config_content)?; |
| 248 | |
| 249 | // Try to find the identity directory |
| 250 | // The store uses {name}-{usage}-{id_short} as directory names, |
| 251 | // but we can also match by the ID directly |
| 252 | load_identity_by_id(&identities_dir, &default_id) |
| 253 | .or_else(|| load_identity_by_scanning(&identities_dir, &default_id)) |
| 254 | } |
| 255 | |
| 256 | /// Get the default identities directory: `~/.atomic/identities/` |
| 257 | fn default_identities_dir() -> Option<PathBuf> { |
no test coverage detected