From 7a26e8bd659e14ecd7da309619c797c995a02a9a Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Sun, 30 Dec 2018 15:59:40 +0100 Subject: [PATCH] ignore non-existent CWDs (fixes #586) --- .../src/services/sessions.service.ts | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/terminus-terminal/src/services/sessions.service.ts b/terminus-terminal/src/services/sessions.service.ts index 72d5eb69..a05e3b60 100644 --- a/terminus-terminal/src/services/sessions.service.ts +++ b/terminus-terminal/src/services/sessions.service.ts @@ -104,16 +104,24 @@ export class Session extends BaseSession { LC_MONETARY: locale, }) } + + let cwd = options.cwd || process.env.HOME + + if (!fs.existsSync(cwd)) { + console.warn('Ignoring non-existent CWD:', cwd) + cwd = null + } + this.pty = nodePTY.spawn(options.command, options.args || [], { name: 'xterm-256color', cols: options.width || 80, rows: options.height || 30, - cwd: options.cwd || process.env.HOME, + cwd, env: env, experimentalUseConpty: this.config.store.terminal.useConPTY, }) - this.guessedCWD = options.cwd || process.env.HOME + this.guessedCWD = cwd this.truePID = (this.pty as any).pid @@ -252,6 +260,14 @@ export class Session extends BaseSession { return fs.readlink(`/proc/${this.truePID}/cwd`) } if (process.platform === 'win32') { + if (!this.guessedCWD) { + return null + } + try { + fs.access(this.guessedCWD) + } catch (e) { + return null + } return this.guessedCWD } return null