From 430482720765c609506a6701e725404a4abf9e1c Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Tue, 12 Oct 2010 10:56:55 -0700 Subject: [PATCH] if TMPDIR is not set in the environment try /tmp and fallback to cwd --- lib/index.js | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/index.js b/lib/index.js index 6b62414..8a11a51 100644 --- a/lib/index.js +++ b/lib/index.js @@ -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']