Skip to content

Commit

Permalink
Merge pull request #156 from bengourley/master
Browse files Browse the repository at this point in the history
Look for more potential tmp dir locations
  • Loading branch information
felixge committed Jul 8, 2012
2 parents dd8dd7a + 7b6bbe5 commit 9ca2b4d
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Readme.md
Expand Up @@ -179,7 +179,7 @@ __incomingForm.encoding = 'utf-8'__

The encoding to use for incoming form fields.

__incomingForm.uploadDir = process.env.TMP || '/tmp' || process.cwd()__
__incomingForm.uploadDir = process.env.TMP || process.env.TMPDIR || process.env.TEMP || '/tmp' || process.cwd()__

The directory for placing file uploads in. You can move them later on using
`fs.rename()`. The default directory is picked at module load time depending on
Expand Down
12 changes: 9 additions & 3 deletions lib/incoming_form.js
Expand Up @@ -10,12 +10,12 @@ var util = require('./util'),
EventEmitter = require('events').EventEmitter,
Stream = require('stream').Stream;

function IncomingForm(opts) {
function IncomingForm(opts) {
if (!(this instanceof IncomingForm)) return new IncomingForm;
EventEmitter.call(this);

opts=opts||{};

this.error = null;
this.ended = false;

Expand All @@ -38,7 +38,13 @@ util.inherits(IncomingForm, EventEmitter);
exports.IncomingForm = IncomingForm;

IncomingForm.UPLOAD_DIR = (function() {
var dirs = [process.env.TMP, '/tmp', process.cwd()];
var dirs = [
process.env.TMP,
process.env.TMPDIR,
process.env.TEMP,
'/tmp',
process.cwd()
];
for (var i = 0; i < dirs.length; i++) {
var dir = dirs[i];
var isDirectory = false;
Expand Down
7 changes: 6 additions & 1 deletion test/legacy/simple/test-incoming-form.js
Expand Up @@ -29,7 +29,12 @@ test(function constructor() {
assert.strictEqual(form.type, null);
assert.strictEqual(form.headers, null);
assert.strictEqual(form.keepExtensions, false);
assert.strictEqual(form.uploadDir, '/tmp');
// Can't assume dir === '/tmp' for portability
// assert.strictEqual(form.uploadDir, '/tmp');
// Make sure it is a directory instead
assert.doesNotThrow(function () {
assert(fs.statSync(form.uploadDir).isDirectory());
});
assert.strictEqual(form.encoding, 'utf-8');
assert.strictEqual(form.bytesReceived, null);
assert.strictEqual(form.bytesExpected, null);
Expand Down

0 comments on commit 9ca2b4d

Please sign in to comment.