Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
os: remove trailing slash from os.tmpdir()
This commit makes `os.tmpdir()` behave consistently on all platforms. It
changes `os.tmpdir()` to always return a path without trailing slash.

Semver: major
Fixes: #715
PR-URL: #747
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
  • Loading branch information
tellnes committed Mar 21, 2015
commit bb97b70eb709b0e0470a5164b3722c292859618a
8 changes: 6 additions & 2 deletions lib/os.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,20 @@ exports.platform = function() {
};

exports.tmpdir = function() {
var path;
if (isWindows) {
return process.env.TEMP ||
path = process.env.TEMP ||
process.env.TMP ||
(process.env.SystemRoot || process.env.windir) + '\\temp';
} else {
return process.env.TMPDIR ||
path = process.env.TMPDIR ||
process.env.TMP ||
process.env.TEMP ||
'/tmp';
}
if (/[\\\/]$/.test(path))
path = path.slice(0, -1);
return path;
};

exports.tmpDir = exports.tmpdir;
Expand Down
4 changes: 4 additions & 0 deletions test/parallel/test-os.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ if (process.platform === 'win32') {
process.env.TMP = '';
var expected = (process.env.SystemRoot || process.env.windir) + '\\temp';
assert.equal(os.tmpdir(), expected);
process.env.TEMP = '\\temp\\';
assert.equal(os.tmpdir(), '\\temp');
} else {
assert.equal(os.tmpdir(), '/tmpdir');
process.env.TMPDIR = '';
Expand All @@ -21,6 +23,8 @@ if (process.platform === 'win32') {
assert.equal(os.tmpdir(), '/temp');
process.env.TEMP = '';
assert.equal(os.tmpdir(), '/tmp');
process.env.TMPDIR = '/tmpdir/';
assert.equal(os.tmpdir(), '/tmpdir');
}

var endianness = os.endianness();
Expand Down