Skip to content

Commit

Permalink
Expand user in the CodeChecker binary path
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
csordasmarton committed Feb 28, 2022
1 parent a458bc9 commit a4bd18e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/backend/executor/process.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as child_process from 'child_process';
import * as os from 'os';
import { quote } from 'shell-quote';
import { Disposable, Event, EventEmitter, ExtensionContext, workspace } from 'vscode';

Expand All @@ -19,6 +20,13 @@ export enum ProcessType {
other = 'Other process',
}

const homeDir = os.homedir();

// Expand an initial '~' component in the given path if there is any, otherwise returns the file path without changes.
function expandUser(filePath: string) {
return homeDir ? filePath.replace(/^~(?=$|\/|\\)/, homeDir) : filePath;
}

export interface ProcessParameters {
/** Default: true, false when type is parse */
forwardStdoutToLogs?: boolean,
Expand Down Expand Up @@ -84,7 +92,7 @@ export class ScheduledProcess implements Disposable {
}

constructor(executable: string, commandArgs?: string[], parameters?: ProcessParameters) {
this.executable = executable;
this.executable = expandUser(executable);
this.commandArgs = commandArgs ?? [];
this.processParameters = parameters ?? {};

Expand Down

0 comments on commit a4bd18e

Please sign in to comment.