Skip to content

Commit

Permalink
Fixed bug in code that scans for source files within the project that…
Browse files Browse the repository at this point in the history
… caused an infinite loop if it encountered a symbolic link that created a cycle.
  • Loading branch information
msfterictraut committed Jun 18, 2020
1 parent 2f29930 commit afceb82
Showing 1 changed file with 17 additions and 14 deletions.
31 changes: 17 additions & 14 deletions server/src/common/pathUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -553,28 +553,31 @@ export function isFile(fs: FileSystem, path: string): boolean {

export function getFileSystemEntries(fs: FileSystem, path: string): FileSystemEntries {
try {
const entries = fs.readdirSync(path || '.').sort();
const entries = fs.readdirEntriesSync(path || '.').sort((a, b) => {
if (a.name < b.name) {
return -1;
} else if (a.name > b.name) {
return 1;
} else {
return 0;
}
});
const files: string[] = [];
const directories: string[] = [];
for (const entry of entries) {
// This is necessary because on some file system node fails to exclude
// "." and "..". See https://github.com/nodejs/node/issues/4002
if (entry === '.' || entry === '..') {
if (entry.name === '.' || entry.name === '..') {
continue;
}
const name = combinePaths(path, entry);

let stat: any;
try {
stat = fs.statSync(name);
} catch (e) {
continue;
}

if (stat.isFile()) {
files.push(entry);
} else if (stat.isDirectory()) {
directories.push(entry);
if (entry.isFile()) {
files.push(entry.name);
} else if (entry.isDirectory()) {
// Don't traverse symbolic links. They can lead to cycles.
if (!entry.isSymbolicLink()) {
directories.push(entry.name);
}
}
}
return { files, directories };
Expand Down

0 comments on commit afceb82

Please sign in to comment.