فهرست منبع

defer tempfile cleanup

Eugene Pankov 3 سال پیش
والد
کامیت
b017588537
2فایلهای تغییر یافته به همراه6 افزوده شده و 6 حذف شده
  1. 4 5
      tabby-ssh/src/services/ssh.service.ts
  2. 2 1
      web/polyfills.ts

+ 4 - 5
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)]
         const args = [await this.getWinSCPURI(session.profile, undefined, session.authUsername ?? undefined)]
 
 
+        let tmpFile: tmp.FileResult|null = null
         if (session.activePrivateKey) {
         if (session.activePrivateKey) {
-            const tmpFile = await tmp.file()
+            tmpFile = await tmp.file()
             const privateKey = await sshpk.parsePrivateKey(session.activePrivateKey, 'auto')/* .toString('putty') */
             const privateKey = await sshpk.parsePrivateKey(session.activePrivateKey, 'auto')/* .toString('putty') */
             const forgePrivateKey = forge.pki.decryptRsaPrivateKey(privateKey.toString('pem'))
             const forgePrivateKey = forge.pki.decryptRsaPrivateKey(privateKey.toString('pem'))
             const ppk = forge.ssh.privateKeyToPutty(forgePrivateKey)
             const ppk = forge.ssh.privateKeyToPutty(forgePrivateKey)
             await fs.writeFile(tmpFile.path, ppk)
             await fs.writeFile(tmpFile.path, ppk)
             args.push(`/privatekey=${tmpFile.path}`)
             args.push(`/privatekey=${tmpFile.path}`)
-            setTimeout(() => {
-                tmpFile.cleanup()
-            }, 5000)
         }
         }
-        this.platform.exec(path, args)
+        await this.platform.exec(path, args)
+        tmpFile?.cleanup()
     }
     }
 }
 }
 
 

+ 2 - 1
web/polyfills.ts

@@ -48,7 +48,7 @@ Tabby.registerMock('fs', {
     appendFile: () => null,
     appendFile: () => null,
     constants: {},
     constants: {},
 })
 })
-Tabby.registerMock('any-promise', Promise)
+Tabby.registerMock('fs/promises', {})
 Tabby.registerMock('tls', {})
 Tabby.registerMock('tls', {})
 Tabby.registerMock('module', {
 Tabby.registerMock('module', {
     globalPaths: [],
     globalPaths: [],
@@ -92,6 +92,7 @@ Tabby.registerMock('keytar', {
 })
 })
 Tabby.registerMock('@serialport/bindings', {})
 Tabby.registerMock('@serialport/bindings', {})
 Tabby.registerMock('@serialport/bindings-cpp', {})
 Tabby.registerMock('@serialport/bindings-cpp', {})
+Tabby.registerMock('tmp', {})
 
 
 Tabby.registerModule('net', {
 Tabby.registerModule('net', {
     Socket: SocketProxy,
     Socket: SocketProxy,