Skip to content
Browse files

Use module 'tmp' instead of 'temp'.

'temp' seems to be incompatible with Node.js 0.6.x as it still relies
on the 'sys' module.

'tmp' on the other hand seems to have been updated recently and have
better version history on http://search.npmjs.org/#/tmp
  • Loading branch information...
1 parent a196700 commit 685c7b8decb1b02f4129276040d09d274f2bc881 @StanAngeloff committed Dec 13, 2011
Showing with 13 additions and 122 deletions.
  1. +11 −12 lib/lotte.js
  2. +0 −109 lib/temp.js
  3. +2 −1 package.json
View
23 lib/lotte.js
@@ -5,27 +5,26 @@ const STATUS_KILLED = 'killed';
var childProcess = require('child_process'),
fs = require('fs'),
path = require('path'),
+ tmp = require('tmp'),
console = require('./console'),
events = require('./events'),
- utils = require('./utils'),
- temp = require('./temp');
+ utils = require('./utils');
var __basename = path.basename(__filename, '.js');
-function mktemp(options, resume) {
+function mktemp(options, extension, resume) {
options.garbage || (options.garbage = []);
- /*utils.exec((options.mktemp) + ' -t ' + __basename + '.XXXXXX', function(e, stdout) {
+ tmp.file({
+ prefix: __basename + '-',
+ postfix: extension,
+ keep: true,
+ }, function(e, temporary) {
if (e) {
return resume(e);
}
- var temporary = stdout.trim();
options.garbage.push(temporary);
resume(null, temporary);
- });*/
-
- var temporary = temp.path({ prefix: 'lotte.XXXXXX.' });
- options.garbage.push(temporary);
- resume(null, temporary);
+ });
};
function cache(options, resume) {
@@ -83,7 +82,7 @@ function cache(options, resume) {
};
include(main);
remaining = remaining + 1;
- mktemp(options, function(e, temporary) {
+ mktemp(options, '.cookies', function(e, temporary) {
options.cache.cookieFile = temporary;
completed(e);
});
@@ -181,7 +180,7 @@ function substitute(template, file, code, options) {
};
function processOne(file, template, options, resume) {
- mktemp(options, function(e, temporary) {
+ mktemp(options, '.js', function(e, temporary) {
if (e) {
return resume(e);
}
View
109 lib/temp.js
@@ -1,109 +0,0 @@
-var util = require('util'),
- fs = require('fs'),
- path = require('path');
-
-/* HELPERS */
-
-var defaultDirectory = '/tmp';
-var environmentVariables = ['TMPDIR', 'TMP', 'TEMP'];
-
-var findDirectory = function() {
- for(var i = 0; i < environmentVariables.length; i++) {
- var value = process.env[environmentVariables[i]];
- if(value)
- return fs.realpathSync(value);
- }
- return fs.realpathSync(defaultDirectory);
-}
-
-var generateName = function(rawAffixes, defaultPrefix) {
- var affixes = parseAffixes(rawAffixes, defaultPrefix);
- var now = new Date();
- var name = [affixes.prefix,
- now.getYear(), now.getMonth(), now.getDay(),
- '-',
- process.pid,
- '-',
- (Math.random() * 0x100000000 + 1).toString(36),
- affixes.suffix].join('');
- return path.join(exports.dir, name);
-}
-
-var parseAffixes = function(rawAffixes, defaultPrefix) {
- var affixes = {prefix: null, suffix: null};
- if(rawAffixes) {
- switch (typeof(rawAffixes)) {
- case 'string':
- affixes.prefix = rawAffixes;
- break;
- case 'object':
- affixes = rawAffixes;
- break
- default:
- throw("Unknown affix declaration: " + affixes);
- }
- } else {
- affixes.prefix = defaultPrefix;
- }
- return affixes;
-}
-
-/* DIRECTORIES */
-
-var mkdir = function(affixes, callback) {
- var dirPath = generateName(affixes, 'd-');
- fs.mkdir(dirPath, 0700, function(err) {
- if (!err) {
- process.addListener('exit', function() {
- try { fs.rmdirSync(dirPath); }
- catch (rmErr) { /* removed normally */ }
- } );
- }
- if (callback)
- callback(err, dirPath);
- });
-}
-var mkdirSync = function(affixes) {
- var dirPath = generateName(affixes, 'd-');
- fs.mkdirSync(dirPath, 0700);
- process.addListener('exit', function() {
- try { fs.rmdirSync(dirPath) }
- catch (rmErr) { /* removed manually */ }
- } );
- return dirPath;
-}
-
-/* FILES */
-
-var open = function(affixes, callback) {
- var filePath = generateName(affixes, 'f-')
- fs.open(filePath, 'w+', 0600, function(err, fd) {
- if (!err)
- process.addListener('exit', function() {
- try { fs.unlinkSync(filePath); }
- catch (rmErr) { /* removed normally */ }
- });
- if (callback)
- callback(err, {path: filePath, fd: fd});
- });
-}
-
-var openSync = function(affixes) {
- var filePath = generateName(affixes, 'f-')
- var fd = fs.openSync(filePath, "w+", 0600);
- process.addListener('exit', function() {
- try { fs.unlinkSync(filePath); }
- catch (rmErr) { /* removed manually */ }
- });
- return {path: filePath, fd: fd};
-}
-
-
-/* EXPORTS */
-
-exports.dir = findDirectory();
-exports.mkdir = mkdir;
-exports.mkdirSync = mkdirSync;
-exports.open = open;
-exports.openSync = openSync;
-exports.path = generateName;
View
3 package.json
@@ -20,7 +20,8 @@
"minimatch": "~0.0.4",
"naturalsort": "~0.0.1",
"optimist": "~0.3.0",
- "semver": "~1.0.12"
+ "semver": "~1.0.12",
+ "tmp": "~0.0.12"
},
"devDependencies": {
"express": "~2.5.0"

0 comments on commit 685c7b8

Please sign in to comment.
Something went wrong with that request. Please try again.