Permalink
Browse files

os: use %SystemRoot% or %windir% in os.tmpdir()

On Windows, respect the SystemRoot and windir environment variables,
don't default to c:\windows\temp.
  • Loading branch information...
1 parent 1f55704 commit 120e5a24df76deb5019abec9744ace94f0f3746a @doortts doortts committed with bnoordhuis Mar 19, 2013
Showing with 13 additions and 6 deletions.
  1. +13 −6 lib/os.js
View
@@ -21,6 +21,7 @@
var binding = process.binding('os');
var util = require('util');
+var isWindows = process.platform === 'win32';
exports.endianness = binding.getEndianness;
exports.hostname = binding.getHostname;
@@ -42,16 +43,22 @@ exports.platform = function() {
};
exports.tmpdir = function() {
- return process.env.TMPDIR ||
- process.env.TMP ||
- process.env.TEMP ||
- (process.platform === 'win32' ? 'c:\\windows\\temp' : '/tmp');
-};
+ if (isWindows) {
+ return process.env.TEMP ||
+ process.env.TMP ||
+ (process.env.SystemRoot || process.env.windir) + "\\temp";
+ } else {
+ return process.env.TMPDIR ||
+ process.env.TMP ||
+ process.env.TEMP ||
+ '/tmp';
+ }
+}
exports.tmpDir = exports.tmpdir;
exports.getNetworkInterfaces = util.deprecate(function() {
return exports.networkInterfaces();
}, 'getNetworkInterfaces is now called `os.networkInterfaces`.');
-exports.EOL = process.platform === 'win32' ? '\r\n' : '\n';
+exports.EOL = isWindows ? '\r\n' : '\n';

5 comments on commit 120e5a2

This introduces lint errors.

Fixed on 9100dd4, but please run make test or make jslint next time.

Also, make jslintfix will correct any lint problems that are machine-correctible.

It also broke the unit tests on Windows. (Specifically simple/test-os (log).)

Hey, @doortts, what motivated changing the order of TMPDIR, TMP, and TEMP on Windows (and removing TMPDIR altogether, for that matter)? I understand the case for constructing a default using systemroot or windir. Just not the rest.

when I spoke to @piscisaureus he wanted it to respect the ordained windows order? so I think we want to update the test in a way that makes everyone happy

Works for me--I'll update the test.

Please sign in to comment.