Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge v8 changes #1506

Closed
wants to merge 6 commits into from
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
Next Next 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 authored and chrisdickinson committed Apr 24, 2015
commit 30b4f81873b2908c5a08af1dde42f6217a8cdbe8
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