From b017588537be9e0fb6cd11b5f49ecdcb7fd52493 Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Tue, 27 Sep 2022 23:12:59 +0200 Subject: [PATCH] defer tempfile cleanup --- tabby-ssh/src/services/ssh.service.ts | 9 ++++----- web/polyfills.ts | 3 ++- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/tabby-ssh/src/services/ssh.service.ts b/tabby-ssh/src/services/ssh.service.ts index 4944850d..5189a1e1 100644 --- a/tabby-ssh/src/services/ssh.service.ts +++ b/tabby-ssh/src/services/ssh.service.ts @@ -50,18 +50,17 @@ export class SSHService { } const args = [await this.getWinSCPURI(session.profile, undefined, session.authUsername ?? undefined)] + let tmpFile: tmp.FileResult|null = null if (session.activePrivateKey) { - const tmpFile = await tmp.file() + tmpFile = await tmp.file() const privateKey = await sshpk.parsePrivateKey(session.activePrivateKey, 'auto')/* .toString('putty') */ const forgePrivateKey = forge.pki.decryptRsaPrivateKey(privateKey.toString('pem')) const ppk = forge.ssh.privateKeyToPutty(forgePrivateKey) await fs.writeFile(tmpFile.path, ppk) args.push(`/privatekey=${tmpFile.path}`) - setTimeout(() => { - tmpFile.cleanup() - }, 5000) } - this.platform.exec(path, args) + await this.platform.exec(path, args) + tmpFile?.cleanup() } } diff --git a/web/polyfills.ts b/web/polyfills.ts index 404d34c7..1aa5e2b2 100644 --- a/web/polyfills.ts +++ b/web/polyfills.ts @@ -48,7 +48,7 @@ Tabby.registerMock('fs', { appendFile: () => null, constants: {}, }) -Tabby.registerMock('any-promise', Promise) +Tabby.registerMock('fs/promises', {}) Tabby.registerMock('tls', {}) Tabby.registerMock('module', { globalPaths: [], @@ -92,6 +92,7 @@ Tabby.registerMock('keytar', { }) Tabby.registerMock('@serialport/bindings', {}) Tabby.registerMock('@serialport/bindings-cpp', {}) +Tabby.registerMock('tmp', {}) Tabby.registerModule('net', { Socket: SocketProxy,