Skip to content

Commit d8017f4

Browse files
committed
Expand user in the CodeChecker binary path
We are using `spawn` method to execute a CodeChecker command. If the executable path starts with a `~` (e.g.: `~/CodeChecker/bin/CodeChecker`), the `spawn` method doesn't work properly and will give an exception. For more information see: nodejs/node#684 To solve this problem we will expand the `~` in the file path before executing the command.
1 parent a458bc9 commit d8017f4

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

src/backend/executor/process.ts

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import * as child_process from 'child_process';
2+
import * as os from 'os';
23
import { quote } from 'shell-quote';
34
import { Disposable, Event, EventEmitter, ExtensionContext, workspace } from 'vscode';
45

@@ -19,6 +20,11 @@ export enum ProcessType {
1920
other = 'Other process',
2021
}
2122

23+
// Expand an initial '~' component in the given path if there is any, otherwise returns the file path without changes.
24+
function expandUser(filePath: string) {
25+
return os.homedir ? filePath.replace(/^~(?=$|\/|\\)/, os.homedir) : filePath;
26+
}
27+
2228
export interface ProcessParameters {
2329
/** Default: true, false when type is parse */
2430
forwardStdoutToLogs?: boolean,
@@ -84,7 +90,7 @@ export class ScheduledProcess implements Disposable {
8490
}
8591

8692
constructor(executable: string, commandArgs?: string[], parameters?: ProcessParameters) {
87-
this.executable = executable;
93+
this.executable = expandUser(executable);
8894
this.commandArgs = commandArgs ?? [];
8995
this.processParameters = parameters ?? {};
9096

0 commit comments

Comments
 (0)