(opencode_dir: &Path)
| 107 | } |
| 108 | |
| 109 | fn db_path(opencode_dir: &Path) -> Option<PathBuf> { |
| 110 | let default_path = opencode_dir.join("opencode.db"); |
| 111 | if default_path.is_file() { |
| 112 | return Some(default_path); |
| 113 | } |
| 114 | let mut candidates = fs::read_dir(opencode_dir) |
| 115 | .ok()? |
| 116 | .filter_map(std::result::Result::ok) |
| 117 | .map(|entry| entry.path()) |
| 118 | .filter(|path| { |
| 119 | path.is_file() |
| 120 | && path |
| 121 | .file_name() |
| 122 | .and_then(|name| name.to_str()) |
| 123 | .is_some_and(is_channel_db_name) |
| 124 | }) |
| 125 | .collect::<Vec<_>>(); |
| 126 | candidates.sort(); |
| 127 | candidates.into_iter().next() |
| 128 | } |
| 129 | |
| 130 | fn is_channel_db_name(name: &str) -> bool { |
| 131 | name.starts_with("opencode-") |
no test coverage detected