Scan todos directory and return all rows
(&self)
| 146 | |
| 147 | /// Scan todos directory and return all rows |
| 148 | fn scan_todos(&self) -> Result<Vec<(Key, DataRow)>> { |
| 149 | let todos_dir = self.config.todos_dir(); |
| 150 | if !todos_dir.exists() { |
| 151 | return Ok(Vec::new()); |
| 152 | } |
| 153 | |
| 154 | let mut rows = Vec::new(); |
| 155 | let mut row_id: i64 = 0; |
| 156 | |
| 157 | let entries = fs::read_dir(&todos_dir) |
| 158 | .map_err(|e| GlueError::StorageMsg(format!("Failed to read todos dir: {}", e)))?; |
| 159 | |
| 160 | for entry in entries.flatten() { |
| 161 | let path = entry.path(); |
| 162 | if path.extension().is_some_and(|ext| ext == "json") { |
| 163 | let source_file = path |
| 164 | .file_name() |
| 165 | .and_then(|n| n.to_str()) |
| 166 | .unwrap_or("unknown") |
| 167 | .to_string(); |
| 168 | |
| 169 | let (workspace_id, agent_id) = parse_todo_filename(&source_file); |
| 170 | |
| 171 | if let Ok(content) = fs::read_to_string(&path) { |
| 172 | if let Ok(json) = serde_json::from_str::<JsonValue>(&content) { |
| 173 | match json { |
| 174 | JsonValue::Array(items) => { |
| 175 | for item in items { |
| 176 | let data_row = todo_json_to_data_row( |
| 177 | &item, |
| 178 | &source_file, |
| 179 | &workspace_id, |
| 180 | &agent_id, |
| 181 | ); |
| 182 | rows.push((Key::I64(row_id), data_row)); |
| 183 | row_id += 1; |
| 184 | } |
| 185 | } |
| 186 | JsonValue::Object(_) => { |
| 187 | let data_row = todo_json_to_data_row( |
| 188 | &json, |
| 189 | &source_file, |
| 190 | &workspace_id, |
| 191 | &agent_id, |
| 192 | ); |
| 193 | rows.push((Key::I64(row_id), data_row)); |
| 194 | row_id += 1; |
| 195 | } |
| 196 | _ => {} |
| 197 | } |
| 198 | } |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | Ok(rows) |
| 204 | } |
| 205 |
no test coverage detected