| 827 | // an ancestor from looping forever and stops a linked subtree being scanned |
| 828 | // twice. |
| 829 | function walkTextFiles(repoRoot, rel = "", seen = new Set()) { |
| 830 | const abs = path.join(repoRoot, rel); |
| 831 | try { |
| 832 | const real = fs.realpathSync(abs); |
| 833 | if (seen.has(real)) return []; |
| 834 | seen.add(real); |
| 835 | } catch (e) { |
| 836 | return []; |
| 837 | } |
| 838 | const out = []; |
| 839 | let entries; |
| 840 | try { |
| 841 | entries = fs.readdirSync(abs, { withFileTypes: true }); |
| 842 | } catch (e) { |
| 843 | return out; |
| 844 | } |
| 845 | // Sorted so annotations come out in a stable order run to run. |
| 846 | entries.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0)); |
| 847 | for (const entry of entries) { |
| 848 | const childRel = rel ? `${rel}/${entry.name}` : entry.name; |
| 849 | let isDir = entry.isDirectory(); |
| 850 | let isFile = entry.isFile(); |
| 851 | if (!isDir && !isFile) { |
| 852 | if (!entry.isSymbolicLink()) continue; // socket, FIFO, device |
| 853 | try { |
| 854 | const stat = fs.statSync(path.join(abs, entry.name)); // follows the link |
| 855 | isDir = stat.isDirectory(); |
| 856 | isFile = stat.isFile(); |
| 857 | } catch (e) { |
| 858 | continue; // dangling link |
| 859 | } |
| 860 | } |
| 861 | if (isDir) { |
| 862 | if (SCAN_SKIP_DIRS.has(entry.name)) continue; |
| 863 | out.push(...walkTextFiles(repoRoot, childRel, seen)); |
| 864 | } else if (isFile) { |
| 865 | out.push(childRel); |
| 866 | } |
| 867 | } |
| 868 | return out; |
| 869 | } |
| 870 | |
| 871 | function probeKind(repoRoot, repoPath) { |
| 872 | try { |