* Finds the highest task ID from existing task files (not including high water mark).
(taskListId: string)
| 245 | * Finds the highest task ID from existing task files (not including high water mark). |
| 246 | */ |
| 247 | async function findHighestTaskIdFromFiles(taskListId: string): Promise<number> { |
| 248 | const dir = getTasksDir(taskListId) |
| 249 | let files: string[] |
| 250 | try { |
| 251 | files = await readdir(dir) |
| 252 | } catch { |
| 253 | return 0 |
| 254 | } |
| 255 | let highest = 0 |
| 256 | for (const file of files) { |
| 257 | if (!file.endsWith('.json')) { |
| 258 | continue |
| 259 | } |
| 260 | const taskId = parseInt(file.replace('.json', ''), 10) |
| 261 | if (!isNaN(taskId) && taskId > highest) { |
| 262 | highest = taskId |
| 263 | } |
| 264 | } |
| 265 | return highest |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * Finds the highest task ID ever assigned, considering both existing files |
no test coverage detected