From a4bd18e979a7492c1a2e22da0583aeabdb18d7f9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A1rton=20Csord=C3=A1s?= Date: Wed, 23 Feb 2022 11:18:16 +0100 Subject: [PATCH] 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. --- src/backend/executor/process.ts | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/backend/executor/process.ts b/src/backend/executor/process.ts index 4bbf92a..59f690a 100644 --- a/src/backend/executor/process.ts +++ b/src/backend/executor/process.ts @@ -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'; @@ -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, @@ -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 ?? {};