Locate the OpenCode database, if present. Checks `$OPENCODE_HOME`, then `$XDG_DATA_HOME/opencode`, then `~/.local/share/opencode` (OpenCode's default data directory on both Linux and macOS), then the platform data dir as a last resort.
()
| 87 | /// `~/.local/share/opencode` (OpenCode's default data directory on both |
| 88 | /// Linux and macOS), then the platform data dir as a last resort. |
| 89 | fn locate_db() -> Option<PathBuf> { |
| 90 | let mut candidates: Vec<PathBuf> = Vec::new(); |
| 91 | if let Some(home) = std::env::var_os("OPENCODE_HOME") { |
| 92 | candidates.push(PathBuf::from(home)); |
| 93 | } |
| 94 | if let Some(xdg) = std::env::var_os("XDG_DATA_HOME") { |
| 95 | candidates.push(PathBuf::from(xdg).join("opencode")); |
| 96 | } |
| 97 | if let Some(home) = dirs::home_dir() { |
| 98 | candidates.push(home.join(".local").join("share").join("opencode")); |
| 99 | } |
| 100 | if let Some(data) = dirs::data_dir() { |
| 101 | candidates.push(data.join("opencode")); |
| 102 | } |
| 103 | |
| 104 | candidates |
| 105 | .into_iter() |
| 106 | .map(|dir| dir.join(DB_FILENAME)) |
| 107 | .find(|path| path.is_file()) |
| 108 | } |
| 109 | |
| 110 | /// Read the current turn's data for `session_id` from OpenCode's store. |
| 111 | /// |