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