git: cleanup ipc handles on deactivate

related to #7758
This commit is contained in:
Joao Moreno 2018-05-03 09:12:05 +02:00
parent 11073cedd3
commit ee582714b6
2 changed files with 9 additions and 0 deletions

View file

@ -10,6 +10,7 @@ import { denodeify } from './util';
import * as path from 'path';
import * as http from 'http';
import * as os from 'os';
import * as fs from 'fs';
import * as crypto from 'crypto';
const randomBytes = denodeify<Buffer>(crypto.randomBytes);
@ -38,6 +39,7 @@ export class Askpass implements Disposable {
private server: http.Server;
private ipcHandlePathPromise: Promise<string>;
private ipcHandlePath: string | undefined;
private enabled = true;
constructor() {
@ -52,6 +54,7 @@ export class Askpass implements Disposable {
const buffer = await randomBytes(20);
const nonce = buffer.toString('hex');
const ipcHandlePath = getIPCHandlePath(nonce);
this.ipcHandlePath = ipcHandlePath;
try {
this.server.listen(ipcHandlePath);
@ -110,5 +113,9 @@ export class Askpass implements Disposable {
dispose(): void {
this.server.close();
if (this.ipcHandlePath && process.platform !== 'win32') {
fs.unlinkSync(this.ipcHandlePath);
}
}
}

View file

@ -25,6 +25,8 @@ async function init(context: ExtensionContext, outputChannel: OutputChannel, dis
const pathHint = workspace.getConfiguration('git').get<string>('path');
const info = await findGit(pathHint, path => outputChannel.appendLine(localize('looking', "Looking for git in: {0}", path)));
const askpass = new Askpass();
disposables.push(askpass);
const env = await askpass.getEnv();
const git = new Git({ gitPath: info.path, version: info.version, env });
const model = new Model(git, context.globalState, outputChannel);