| 777 | // an ancestor from looping forever and stops a linked subtree being scanned |
| 778 | // twice. |
| 779 | function walkTextFiles(repoRoot, rel = "", seen = new Set()) { |
| 780 | const abs = path.join(repoRoot, rel); |
| 781 | try { |
| 782 | const real = fs.realpathSync(abs); |
| 783 | if (seen.has(real)) return []; |
| 784 | seen.add(real); |
| 785 | } catch (e) { |
| 786 | return []; |
| 787 | } |
| 788 | const out = []; |
| 789 | let entries; |
| 790 | try { |
| 791 | entries = fs.readdirSync(abs, { withFileTypes: true }); |
| 792 | } catch (e) { |
| 793 | return out; |
| 794 | } |
| 795 | // Sorted so annotations come out in a stable order run to run. |
| 796 | entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)); |
| 797 | for (const entry of entries) { |
| 798 | const childRel = rel ? `${rel}/${entry.name}` : entry.name; |
| 799 | let isDir = entry.isDirectory(); |
| 800 | let isFile = entry.isFile(); |
| 801 | if (!isDir && !isFile) { |
| 802 | if (!entry.isSymbolicLink()) continue; // socket, FIFO, device |
| 803 | try { |
| 804 | const stat = fs.statSync(path.join(abs, entry.name)); // follows the link |
| 805 | isDir = stat.isDirectory(); |
| 806 | isFile = stat.isFile(); |
| 807 | } catch (e) { |
| 808 | continue; // dangling link |
| 809 | } |
| 810 | } |
| 811 | if (isDir) { |
| 812 | if (SCAN_SKIP_DIRS.has(entry.name)) continue; |
| 813 | out.push(...walkTextFiles(repoRoot, childRel, seen)); |
| 814 | } else if (isFile) { |
| 815 | out.push(childRel); |
| 816 | } |
| 817 | } |
| 818 | return out; |
| 819 | } |
| 820 | |
| 821 | function probeKind(repoRoot, repoPath) { |
| 822 | try { |