if TMPDIR is not set in the environment try /tmp and fallback to cwd

This commit is contained in:
Sami Samhuri 2010-10-12 10:56:55 -07:00
parent 01c7ab03ff
commit 4304827207

View file

@ -10,6 +10,18 @@
var fs = require('fs')
, repl = require('repl')
, _repl
, _tmpdir
// Find a suitable directory to store the REPL session
if (process.env['TMPDIR']) _tmpdir = process.env['TMPDIR']
else {
try {
fs.statSync('/tmp')
_tmpdir = '/tmp'
} catch (e) {
_tmpdir = process.cwd()
}
}
exports.startRepl = function() {
console.log('Commands: edit(), run(), stash(filename), unstash(filename), setEditor(editor)')
@ -24,7 +36,7 @@ exports.extend = function(obj) {
var path = require('path')
, spawn = require('child_process').spawn
, sys = require('sys')
, _tmpfile = path.join(process.env['TMPDIR'], 'node-repl-' + process.pid + '.js')
, _tmpfile = path.join(_tmpdir, 'node-repl-' + process.pid + '.js')
obj.edit = function(editor) {
editor = editor || process.ENV['EDITOR']