| 340 | * just-spawned session is in today's leaf, so the newest few suffice. */ |
| 341 | async function recentDatedLeaves(root: string, count: number): Promise<string[]> { |
| 342 | const newestNumeric = async (dir: string, n: number): Promise<string[]> => { |
| 343 | let names: string[]; |
| 344 | try { |
| 345 | names = await readdir(dir); |
| 346 | } catch { |
| 347 | return []; |
| 348 | } |
| 349 | return names |
| 350 | .filter((x) => /^\d+$/.test(x)) |
| 351 | .sort() |
| 352 | .reverse() |
| 353 | .slice(0, n) |
| 354 | .map((x) => join(dir, x)); |
| 355 | }; |
| 356 | const leaves: string[] = []; |
| 357 | for (const y of await newestNumeric(root, 1)) { |
| 358 | for (const m of await newestNumeric(y, 1)) { |