ignore non-existent CWDs (fixes #586)

This commit is contained in:
Eugene Pankov 2018-12-30 15:59:40 +01:00
parent d56287587c
commit 7a26e8bd65

View File

@ -104,16 +104,24 @@ export class Session extends BaseSession {
LC_MONETARY: locale, 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 || [], { this.pty = nodePTY.spawn(options.command, options.args || [], {
name: 'xterm-256color', name: 'xterm-256color',
cols: options.width || 80, cols: options.width || 80,
rows: options.height || 30, rows: options.height || 30,
cwd: options.cwd || process.env.HOME, cwd,
env: env, env: env,
experimentalUseConpty: this.config.store.terminal.useConPTY, experimentalUseConpty: this.config.store.terminal.useConPTY,
}) })
this.guessedCWD = options.cwd || process.env.HOME this.guessedCWD = cwd
this.truePID = (this.pty as any).pid this.truePID = (this.pty as any).pid
@ -252,6 +260,14 @@ export class Session extends BaseSession {
return fs.readlink(`/proc/${this.truePID}/cwd`) return fs.readlink(`/proc/${this.truePID}/cwd`)
} }
if (process.platform === 'win32') { if (process.platform === 'win32') {
if (!this.guessedCWD) {
return null
}
try {
fs.access(this.guessedCWD)
} catch (e) {
return null
}
return this.guessedCWD return this.guessedCWD
} }
return null return null