Skip to content
This repository was archived by the owner on Jul 24, 2019. It is now read-only.

Commit 5e6598f

Browse files
author
Nick Santos
committed
More robust tmp handling
1 parent 9be54c5 commit 5e6598f

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

install.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ var request = require('request')
1818
var url = require('url')
1919
var util = require('./lib/util')
2020
var which = require('which')
21+
var os = require('os')
22+
23+
console.log('NPM ', process.env.npm_config_tmp)
2124

2225
var originalPath = process.env.PATH
2326

@@ -104,15 +107,17 @@ function exit(code) {
104107
function findSuitableTempDirectory() {
105108
var now = Date.now()
106109
var candidateTmpDirs = [
107-
process.env.TMPDIR || process.env.TEMP || process.env.npm_config_tmp,
108-
'/tmp',
110+
process.env.npm_config_tmp,
111+
os.tmpdir(),
109112
path.join(process.cwd(), 'tmp')
110113
]
111114

112115
for (var i = 0; i < candidateTmpDirs.length; i++) {
113-
var candidatePath = path.join(candidateTmpDirs[i], 'phantomjs')
116+
var candidatePath = candidateTmpDirs[i]
117+
if (!candidatePath) continue
114118

115119
try {
120+
candidatePath = path.join(path.resolve(candidatePath), 'phantomjs')
116121
fs.mkdirsSync(candidatePath, '0777')
117122
// Make double sure we have 0777 permissions; some operating systems
118123
// default umask does not allow write by default.
@@ -127,7 +132,7 @@ function findSuitableTempDirectory() {
127132
}
128133

129134
console.error('Can not find a writable tmp directory, please report issue ' +
130-
'on https://github.com/Obvious/phantomjs/issues/59 with as much ' +
135+
'on https://github.com/Medium/phantomjs/issues with as much ' +
131136
'information as possible.')
132137
exit(1)
133138
}

0 commit comments

Comments
 (0)