| 190 | } |
| 191 | |
| 192 | fn runtime_store(repo: &Repository) -> CliResult<Option<SessionStore>> { |
| 193 | let directory = repo.dot_dir().join("sessions"); |
| 194 | // SessionStore::new creates directories. Never call it on an absent store. |
| 195 | match std::fs::metadata(&directory) { |
| 196 | Ok(metadata) if metadata.is_dir() => SessionStore::new(directory) |
| 197 | .map(Some) |
| 198 | .map_err(|e| CliError::Internal(e.into())), |
| 199 | Ok(_) => Err(invalid("Session store is not a directory")), |
| 200 | Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None), |
| 201 | Err(e) => Err(CliError::Internal(e.into())), |
| 202 | } |
| 203 | } |
| 204 | |
| 205 | fn runtime_session(store: Option<&SessionStore>, id: &str) -> CliResult<Option<AgentSession>> { |
| 206 | validate_session(id)?; |