Skip to content

Commit 5ba482e

Browse files
eleanorjboydCopilot
andcommitted
Fix ps1 path casing on case-insensitive filesystems (Windows)
Use fs.readdir to find the actual activate.ps1 filename with correct casing instead of checking hardcoded 'Activate.ps1'/'activate.ps1'. On Windows, pathExists is case-insensitive so the wrong cased path would be returned when the file has different casing. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5b4b9f9 commit 5ba482e

1 file changed

Lines changed: 8 additions & 5 deletions

File tree

src/managers/common/utils.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,11 +183,14 @@ export async function getShellActivationCommands(binDir: string): Promise<{
183183
shellActivation.set(ShellConstants.KSH, [{ executable: '.', args: [path.join(binDir, `activate`)] }]);
184184
shellDeactivation.set(ShellConstants.KSH, [{ executable: 'deactivate' }]);
185185

186-
if (await fs.pathExists(path.join(binDir, 'Activate.ps1'))) {
187-
shellActivation.set(ShellConstants.PWSH, buildPwshActivationCommands(path.join(binDir, 'Activate.ps1')));
188-
shellDeactivation.set(ShellConstants.PWSH, [{ executable: 'deactivate' }]);
189-
} else if (await fs.pathExists(path.join(binDir, 'activate.ps1'))) {
190-
shellActivation.set(ShellConstants.PWSH, buildPwshActivationCommands(path.join(binDir, 'activate.ps1')));
186+
// Use readdir to find the actual ps1 filename with correct casing.
187+
// pathExists with a hardcoded name fails on case-insensitive filesystems (Windows)
188+
// where 'activate.ps1' created by the user would match 'Activate.ps1' in the check,
189+
// causing the returned path to have the wrong case.
190+
const dirFiles = await fs.readdir(binDir).catch(() => [] as string[]);
191+
const ps1File = dirFiles.find((f) => f.toLowerCase() === 'activate.ps1');
192+
if (ps1File) {
193+
shellActivation.set(ShellConstants.PWSH, buildPwshActivationCommands(path.join(binDir, ps1File)));
191194
shellDeactivation.set(ShellConstants.PWSH, [{ executable: 'deactivate' }]);
192195
}
193196

0 commit comments

Comments
 (0)