提交 9bc292a2 编写于 作者: A Alex Ross

Fix findExecutable to check that the path is not a dir

Fixes #83509
上级 62b627ac
......@@ -454,6 +454,14 @@ export namespace win32 {
if (paths === undefined || paths.length === 0) {
return path.join(cwd, command);
}
async function fileExists(path: string): Promise<boolean> {
if (await promisify(fs.exists)(path)) {
return !((await promisify(fs.stat)(path)).isDirectory);
}
return false;
}
// We have a simple file name. We get the path variable from the env
// and try to find the executable on the path.
for (let pathEntry of paths) {
......@@ -464,15 +472,15 @@ export namespace win32 {
} else {
fullPath = path.join(cwd, pathEntry, command);
}
if (await promisify(fs.exists)(fullPath)) {
if (await fileExists(fullPath)) {
return fullPath;
}
let withExtension = fullPath + '.com';
if (await promisify(fs.exists)(withExtension)) {
if (await fileExists(withExtension)) {
return withExtension;
}
withExtension = fullPath + '.exe';
if (await promisify(fs.exists)(withExtension)) {
if (await fileExists(withExtension)) {
return withExtension;
}
}
......
......@@ -1420,6 +1420,14 @@ export class TerminalTaskSystem implements ITaskSystem {
}
}
private async fileExists(path: string): Promise<boolean> {
const uri: URI = resources.toLocalResource(URI.from({ scheme: Schemas.file, path: path }), this.environmentService.configuration.remoteAuthority);
if (await this.fileService.exists(uri)) {
return !((await this.fileService.resolve(uri)).isDirectory);
}
return false;
}
private async findExecutable(command: string, cwd?: string, paths?: string[]): Promise<string> {
// If we have an absolute path then we take it.
if (path.isAbsolute(command)) {
......@@ -1452,15 +1460,15 @@ export class TerminalTaskSystem implements ITaskSystem {
fullPath = path.join(cwd, pathEntry, command);
}
if (await this.fileService.exists(resources.toLocalResource(URI.from({ scheme: Schemas.file, path: fullPath }), this.environmentService.configuration.remoteAuthority))) {
if (await this.fileExists(fullPath)) {
return fullPath;
}
let withExtension = fullPath + '.com';
if (await this.fileService.exists(resources.toLocalResource(URI.from({ scheme: Schemas.file, path: withExtension }), this.environmentService.configuration.remoteAuthority))) {
if (await this.fileExists(withExtension)) {
return withExtension;
}
withExtension = fullPath + '.exe';
if (await this.fileService.exists(resources.toLocalResource(URI.from({ scheme: Schemas.file, path: withExtension }), this.environmentService.configuration.remoteAuthority))) {
if (await this.fileExists(withExtension)) {
return withExtension;
}
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册