Skip to content

Commit

Permalink
fix(file-client): handle symlinks
Browse files Browse the repository at this point in the history
- Prevent crashing file reading when symlink is encountered
  • Loading branch information
AriPerkkio committed Dec 6, 2020
1 parent c1e7439 commit 5c4144f
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/file-client/file-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,18 @@ function constructTreeFromDir(dir: string): string[] {
const currentPath = `${dir}/${fileOrDir}`;
if (isDirectoryIgnored(currentPath)) return;

return fs.lstatSync(currentPath).isDirectory()
? constructTreeFromDir(currentPath)
: currentPath;
const fileStats = fs.lstatSync(currentPath);

if (fileStats.isDirectory()) {
return constructTreeFromDir(currentPath);
}

if (fileStats.isFile()) {
return currentPath;
}

// Ignore non-files and non-directories, e.g. symlinks
return false;
})
.filter(Boolean)
.reduce<string[]>(
Expand Down

0 comments on commit 5c4144f

Please sign in to comment.