mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-28 04:23:32 +01:00
git: isolate ipc env
This commit is contained in:
@@ -20,10 +20,6 @@ function main(argv: string[]): void {
|
||||
return fatal('Wrong number of arguments');
|
||||
}
|
||||
|
||||
if (!process.env['VSCODE_GIT_ASKPASS_HANDLE']) {
|
||||
return fatal('Missing handle');
|
||||
}
|
||||
|
||||
if (!process.env['VSCODE_GIT_ASKPASS_PIPE']) {
|
||||
return fatal('Missing pipe');
|
||||
}
|
||||
@@ -33,10 +29,9 @@ function main(argv: string[]): void {
|
||||
}
|
||||
|
||||
const output = process.env['VSCODE_GIT_ASKPASS_PIPE'] as string;
|
||||
const socketPath = process.env['VSCODE_GIT_ASKPASS_HANDLE'] as string;
|
||||
const request = argv[2];
|
||||
const host = argv[4].substring(1, argv[4].length - 2);
|
||||
const ipcClient = new IPCClient('askpass', socketPath);
|
||||
const ipcClient = new IPCClient('askpass');
|
||||
|
||||
ipcClient.call({ request, host }).then(res => {
|
||||
fs.writeFileSync(output, res + '\n');
|
||||
|
||||
@@ -26,7 +26,7 @@ export class Askpass implements IIPCHandler {
|
||||
};
|
||||
}
|
||||
|
||||
constructor(private ipc: IIPCServer) {
|
||||
constructor(ipc: IIPCServer) {
|
||||
this.disposable = ipc.registerHandler('askpass', this);
|
||||
}
|
||||
|
||||
@@ -46,8 +46,7 @@ export class Askpass implements IIPCHandler {
|
||||
ELECTRON_RUN_AS_NODE: '1',
|
||||
GIT_ASKPASS: path.join(__dirname, 'askpass.sh'),
|
||||
VSCODE_GIT_ASKPASS_NODE: process.execPath,
|
||||
VSCODE_GIT_ASKPASS_MAIN: path.join(__dirname, 'askpass-main.js'),
|
||||
VSCODE_GIT_ASKPASS_HANDLE: this.ipc.ipcHandlePath
|
||||
VSCODE_GIT_ASKPASS_MAIN: path.join(__dirname, 'askpass-main.js')
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -7,7 +7,17 @@ import * as http from 'http';
|
||||
|
||||
export class IPCClient {
|
||||
|
||||
constructor(private handlerName: string, private ipcHandlePath: string) { }
|
||||
private ipcHandlePath: string;
|
||||
|
||||
constructor(private handlerName: string) {
|
||||
const ipcHandlePath = process.env['VSCODE_GIT_IPC_HANDLE'];
|
||||
|
||||
if (!ipcHandlePath) {
|
||||
throw new Error('Missing VSCODE_GIT_IPC_HANDLE');
|
||||
}
|
||||
|
||||
this.ipcHandlePath = ipcHandlePath;
|
||||
}
|
||||
|
||||
call(request: any): Promise<any> {
|
||||
const opts: http.RequestOptions = {
|
||||
|
||||
@@ -48,6 +48,7 @@ export async function createIPCServer(): Promise<IIPCServer> {
|
||||
|
||||
export interface IIPCServer extends Disposable {
|
||||
readonly ipcHandlePath: string | undefined;
|
||||
getEnv(): any;
|
||||
registerHandler(name: string, handler: IIPCHandler): Disposable;
|
||||
}
|
||||
|
||||
@@ -92,6 +93,10 @@ class IPCServer implements IIPCServer, Disposable {
|
||||
});
|
||||
}
|
||||
|
||||
getEnv(): any {
|
||||
return { VSCODE_GIT_IPC_HANDLE: this.ipcHandlePath };
|
||||
}
|
||||
|
||||
dispose(): void {
|
||||
this.handlers.clear();
|
||||
this.server.close();
|
||||
|
||||
@@ -34,15 +34,16 @@ export async function deactivate(): Promise<any> {
|
||||
async function createModel(context: ExtensionContext, outputChannel: OutputChannel, telemetryReporter: TelemetryReporter, disposables: Disposable[]): Promise<Model> {
|
||||
const pathHint = workspace.getConfiguration('git').get<string>('path');
|
||||
const info = await findGit(pathHint, path => outputChannel.appendLine(localize('looking', "Looking for git in: {0}", path)));
|
||||
let env: any = undefined;
|
||||
let env: any = {};
|
||||
|
||||
try {
|
||||
const ipc = await createIPCServer();
|
||||
disposables.push(ipc);
|
||||
env = { ...env, ...ipc.getEnv() };
|
||||
|
||||
const askpass = new Askpass(ipc);
|
||||
disposables.push(askpass);
|
||||
env = askpass.getEnv();
|
||||
env = { ...env, ...askpass.getEnv() };
|
||||
} catch {
|
||||
env = Askpass.getDisabledEnv();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user