Skip to content

Commit 69c71e8

Browse files
committed
Address comments
1 parent 63d3de5 commit 69c71e8

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,17 +106,26 @@ export async function resolveSymbolicLink(absPath: string): Promise<string> {
106106
return absPath;
107107
}
108108

109+
/**
110+
* Returns full path to sub directories of a given directory.
111+
* @param root
112+
* @param resolveSymlinks
113+
*/
109114
export async function* getSubDirs(root: string, resolveSymlinks: boolean): AsyncIterableIterator<string> {
110-
const dirContents = await fsapi.readdir(root);
115+
const dirContents = await fsapi.promises.readdir(root, { withFileTypes: true });
111116
const generators = dirContents.map((item) => {
112117
async function* generator() {
113-
const fullPath = path.join(root, item);
114-
const stat = await fsapi.lstat(fullPath);
115-
116-
if (stat.isDirectory()) {
118+
const fullPath = path.join(root, item.name);
119+
if (item.isDirectory()) {
117120
yield fullPath;
118-
} else if (resolveSymlinks && stat.isSymbolicLink()) {
119-
yield await resolveSymbolicLink(fullPath);
121+
} else if (resolveSymlinks && item.isSymbolicLink()) {
122+
// The current FS item is a symlink. It can potentially be a file
123+
// or a directory. Resolve it first and then check if it is a directory.
124+
const resolvedPath = await resolveSymbolicLink(fullPath);
125+
const resolvedPathStat = await fsapi.lstat(resolvedPath);
126+
if (resolvedPathStat.isDirectory()) {
127+
yield resolvedPath;
128+
}
120129
}
121130
}
122131

0 commit comments

Comments
 (0)