32 lines
777 B
JavaScript
32 lines
777 B
JavaScript
|
// Generated by CoffeeScript 1.9.3
|
||
|
(function() {
|
||
|
var fs, timeout;
|
||
|
|
||
|
fs = require('fs');
|
||
|
|
||
|
timeout = require('./timeout');
|
||
|
|
||
|
module.exports = function() {
|
||
|
var created, dir, i, len, name, ref, t_limit, tmp_dir;
|
||
|
t_limit = Date.now() + 1000;
|
||
|
tmp_dir = '/tmp';
|
||
|
ref = ['TMPDIR', 'TMP', 'TEMP'];
|
||
|
for (i = 0, len = ref.length; i < len; i++) {
|
||
|
name = ref[i];
|
||
|
if ((dir = process.env[name]) != null) {
|
||
|
tmp_dir = dir.replace(/\/$/, '');
|
||
|
}
|
||
|
}
|
||
|
while (!created) {
|
||
|
try {
|
||
|
dir = tmp_dir + '/sync-exec-' + Math.floor(Math.random() * 1000000000);
|
||
|
fs.mkdir(dir);
|
||
|
created = true;
|
||
|
} catch (_error) {}
|
||
|
timeout(t_limit, 'Can not create sync-exec directory');
|
||
|
}
|
||
|
return dir;
|
||
|
};
|
||
|
|
||
|
}).call(this);
|