Skip to content

Commit

Permalink
defer tempfile cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Eugeny committed Sep 28, 2022
1 parent 5f86e10 commit 4675b75
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
9 changes: 4 additions & 5 deletions tabby-ssh/src/services/ssh.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
}

Expand Down
3 changes: 2 additions & 1 deletion web/polyfills.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [],
Expand Down Expand Up @@ -92,6 +92,7 @@ Tabby.registerMock('keytar', {
})
Tabby.registerMock('@serialport/bindings', {})
Tabby.registerMock('@serialport/bindings-cpp', {})
Tabby.registerMock('tmp', {})

Tabby.registerModule('net', {
Socket: SocketProxy,
Expand Down

0 comments on commit 4675b75

Please sign in to comment.