Skip to content

Commit

Permalink
Fix findExecutable to check that the path is not a dir
Browse files Browse the repository at this point in the history
Fixes #83509
  • Loading branch information
alexr00 committed Oct 29, 2019
1 parent 62b627a commit 9bc292a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
14 changes: 11 additions & 3 deletions src/vs/base/node/processes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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;
}
}
Expand Down
14 changes: 11 additions & 3 deletions src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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;
}
}
Expand Down

0 comments on commit 9bc292a

Please sign in to comment.