| 31 | let readErrors = 0; |
| 32 | |
| 33 | const walk = (currentDir, depth) => { |
| 34 | if (depth >= maxDepth || files.length >= maxFiles) { |
| 35 | return; |
| 36 | } |
| 37 | |
| 38 | let entries; |
| 39 | try { |
| 40 | entries = fs.readdirSync(currentDir, { withFileTypes: true }); |
| 41 | } catch (err) { |
| 42 | readErrors += 1; |
| 43 | console.log(`[debug] failed to read ${currentDir}: ${err.message}`); |
| 44 | return; |
| 45 | } |
| 46 | |
| 47 | entries.sort((a, b) => a.name.localeCompare(b.name)); |
| 48 | |
| 49 | for (const entry of entries) { |
| 50 | if (files.length >= maxFiles) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | const fullPath = path.join(currentDir, entry.name); |
| 55 | if (entry.isDirectory()) { |
| 56 | walk(fullPath, depth + 1); |
| 57 | continue; |
| 58 | } |
| 59 | |
| 60 | files.push(path.relative(tmpDir, fullPath) || "."); |
| 61 | } |
| 62 | }; |
| 63 | |
| 64 | walk(tmpDir, 0); |
| 65 | |