Skip to content

Commit c2e9274

Browse files
authored
Calrify that symlinks get resolved while looking for sub-directories (#15512)
1 parent 83fbfdb commit c2e9274

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/client/pythonEnvironments/common/externalDependencies.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,17 +117,22 @@ export async function resolveSymbolicLink(absPath: string): Promise<string> {
117117

118118
/**
119119
* Returns full path to sub directories of a given directory.
120-
* @param root
121-
* @param resolveSymlinks
120+
* @param {string} root : path to get sub-directories from.
121+
* @param options : If called with `resolveSymlinks: true`, then symlinks found in
122+
* the directory are resolved and if they resolve to directories
123+
* then resolved values are returned.
122124
*/
123-
export async function* getSubDirs(root: string, resolveSymlinks: boolean): AsyncIterableIterator<string> {
125+
export async function* getSubDirs(
126+
root: string,
127+
options?: { resolveSymlinks?: boolean },
128+
): AsyncIterableIterator<string> {
124129
const dirContents = await fsapi.promises.readdir(root, { withFileTypes: true });
125130
const generators = dirContents.map((item) => {
126131
async function* generator() {
127132
const fullPath = path.join(root, item.name);
128133
if (item.isDirectory()) {
129134
yield fullPath;
130-
} else if (resolveSymlinks && item.isSymbolicLink()) {
135+
} else if (options?.resolveSymlinks && item.isSymbolicLink()) {
131136
// The current FS item is a symlink. It can potentially be a file
132137
// or a directory. Resolve it first and then check if it is a directory.
133138
const resolvedPath = await resolveSymbolicLink(fullPath);

src/client/pythonEnvironments/discovery/locators/services/pyenvLocator.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ export function parsePyenvVersion(str: string): Promise<IPyenvVersionStrings | u
259259
async function* getPyenvEnvironments(): AsyncIterableIterator<PythonEnvInfo> {
260260
const pyenvVersionDir = getPyenvVersionsDir();
261261

262-
const subDirs = getSubDirs(pyenvVersionDir, true);
262+
const subDirs = getSubDirs(pyenvVersionDir, { resolveSymlinks: true });
263263
for await (const subDirPath of subDirs) {
264264
const envDirName = path.basename(subDirPath);
265265
const interpreterPath = await getInterpreterPathFromDir(subDirPath);

0 commit comments

Comments
 (0)