aboutsummaryrefslogtreecommitdiff
path: root/node_modules/tmp
diff options
context:
space:
mode:
authorFlorian Dold <florian.dold@gmail.com>2016-11-16 01:59:39 +0100
committerFlorian Dold <florian.dold@gmail.com>2016-11-16 02:00:31 +0100
commitbd65bb67e25a79b019d745b7262b2008ce2adb15 (patch)
tree89e1b032103a63737f1a703e6a943832ef261704 /node_modules/tmp
parentf91466595b651721690133f58ab37f977539e95b (diff)
downloadwallet-core-bd65bb67e25a79b019d745b7262b2008ce2adb15.tar.xz
incrementally verify denoms
The denominations are not stored in a separate object store.
Diffstat (limited to 'node_modules/tmp')
-rw-r--r--node_modules/tmp/.travis.yml10
-rw-r--r--node_modules/tmp/README.md144
-rw-r--r--node_modules/tmp/domain-test.js13
-rw-r--r--node_modules/tmp/lib/tmp.js370
-rw-r--r--node_modules/tmp/package.json13
-rwxr-xr-xnode_modules/tmp/test-all.sh9
-rw-r--r--node_modules/tmp/test.js6
-rw-r--r--node_modules/tmp/test/base.js85
-rw-r--r--node_modules/tmp/test/dir-test.js41
-rw-r--r--node_modules/tmp/test/file-test.js20
-rw-r--r--node_modules/tmp/test/graceful.js2
11 files changed, 536 insertions, 177 deletions
diff --git a/node_modules/tmp/.travis.yml b/node_modules/tmp/.travis.yml
index 0175d8220..9c0aa010a 100644
--- a/node_modules/tmp/.travis.yml
+++ b/node_modules/tmp/.travis.yml
@@ -3,3 +3,13 @@ node_js:
- "0.6"
- "0.8"
- "0.10"
+ - "0.12"
+ - "4.0"
+ - "4.1"
+ - "4.2"
+ - "5.0"
+ - "5.1"
+ - "5.2"
+ - "5.3"
+ - "5.4"
+ - "6"
diff --git a/node_modules/tmp/README.md b/node_modules/tmp/README.md
index 3a1a509e9..804bf3395 100644
--- a/node_modules/tmp/README.md
+++ b/node_modules/tmp/README.md
@@ -2,17 +2,21 @@
A simple temporary file and directory creator for [node.js.][1]
-[![Build Status](https://secure.travis-ci.org/raszi/node-tmp.png?branch=master)](http://travis-ci.org/raszi/node-tmp)
+[![Build Status](https://travis-ci.org/raszi/node-tmp.svg?branch=master)](https://travis-ci.org/raszi/node-tmp)
+[![Dependencies](https://david-dm.org/raszi/node-tmp.svg)](https://david-dm.org/raszi/node-tmp)
+[![npm version](https://badge.fury.io/js/tmp.svg)](https://badge.fury.io/js/tmp)
## About
-The main difference between bruce's [node-temp][2] is that mine more
-aggressively checks for the existence of the newly created temporary file and
-creates the new file with `O_EXCL` instead of simple `O_CREAT | O_RDRW`, so it
-is safer.
+This is a [widely used library][2] to create temporary files and directories
+in a [node.js][1] environment.
-The API is slightly different as well, Tmp does not yet provide synchronous
-calls and all the parameters are optional.
+Tmp offers both an asynchronous and a synchronous API. For all API calls, all
+the parameters are optional.
+
+Tmp uses crypto for determining random file names, or, when using templates,
+a six letter random identifier. And just in case that you do not have that much
+entropy left on your system, Tmp will fall back to pseudo random numbers.
You can set whether you want to remove the temporary file on process exit or
not, and the destination directory can also be set.
@@ -25,22 +29,48 @@ npm install tmp
## Usage
-### File creation
+### Asynchronous file creation
-Simple temporary file creation, the file will be unlinked on process exit.
+Simple temporary file creation, the file will be closed and unlinked on process exit.
```javascript
var tmp = require('tmp');
-tmp.file(function _tempFileCreated(err, path, fd) {
+tmp.file(function _tempFileCreated(err, path, fd, cleanupCallback) {
if (err) throw err;
console.log("File: ", path);
console.log("Filedescriptor: ", fd);
+
+ // If we don't need the file anymore we could manually call the cleanupCallback
+ // But that is not necessary if we didn't pass the keep option because the library
+ // will clean after itself.
+ cleanupCallback();
});
```
-### Directory creation
+### Synchronous file creation
+
+A synchronous version of the above.
+
+```javascript
+var tmp = require('tmp');
+
+var tmpobj = tmp.fileSync();
+console.log("File: ", tmpobj.name);
+console.log("Filedescriptor: ", tmpobj.fd);
+
+// If we don't need the file anymore we could manually call the removeCallback
+// But that is not necessary if we didn't pass the keep option because the library
+// will clean after itself.
+tmpobj.removeCallback();
+```
+
+Note that this might throw an exception if either the maximum limit of retries
+for creating a temporary name fails, or, in case that you do not have the permission
+to write to the directory where the temporary file should be created in.
+
+### Asynchronous directory creation
Simple temporary directory creation, it will be removed on process exit.
@@ -49,17 +79,37 @@ If the directory still contains items on process exit, then it won't be removed.
```javascript
var tmp = require('tmp');
-tmp.dir(function _tempDirCreated(err, path) {
+tmp.dir(function _tempDirCreated(err, path, cleanupCallback) {
if (err) throw err;
console.log("Dir: ", path);
+
+ // Manual cleanup
+ cleanupCallback();
});
```
If you want to cleanup the directory even when there are entries in it, then
you can pass the `unsafeCleanup` option when creating it.
-### Filename generation
+### Synchronous directory creation
+
+A synchronous version of the above.
+
+```javascript
+var tmp = require('tmp');
+
+var tmpobj = tmp.dirSync();
+console.log("Dir: ", tmpobj.name);
+// Manual cleanup
+tmpobj.removeCallback();
+```
+
+Note that this might throw an exception if either the maximum limit of retries
+for creating a temporary name fails, or, in case that you do not have the permission
+to write to the directory where the temporary directory should be created in.
+
+### Asynchronous filename generation
It is possible with this library to generate a unique filename in the specified
directory.
@@ -74,9 +124,20 @@ tmp.tmpName(function _tempNameGenerated(err, path) {
});
```
+### Synchronous filename generation
+
+A synchronous version of the above.
+
+```javascript
+var tmp = require('tmp');
+
+var name = tmp.tmpNameSync();
+console.log("Created temporary filename: ", name);
+```
+
## Advanced usage
-### File creation
+### Asynchronous file creation
Creates a file with mode `0644`, prefix will be `prefix-` and postfix will be `.txt`.
@@ -91,7 +152,19 @@ tmp.file({ mode: 0644, prefix: 'prefix-', postfix: '.txt' }, function _tempFileC
});
```
-### Directory creation
+### Synchronous file creation
+
+A synchronous version of the above.
+
+```javascript
+var tmp = require('tmp');
+
+var tmpobj = tmp.fileSync({ mode: 0644, prefix: 'prefix-', postfix: '.txt' });
+console.log("File: ", tmpobj.name);
+console.log("Filedescriptor: ", tmpobj.fd);
+```
+
+### Asynchronous directory creation
Creates a directory with mode `0755`, prefix will be `myTmpDir_`.
@@ -105,7 +178,18 @@ tmp.dir({ mode: 0750, prefix: 'myTmpDir_' }, function _tempDirCreated(err, path)
});
```
-### mkstemps like
+### Synchronous directory creation
+
+Again, a synchronous version of the above.
+
+```javascript
+var tmp = require('tmp');
+
+var tmpobj = tmp.dirSync({ mode: 0750, prefix: 'myTmpDir_' });
+console.log("Dir: ", tmpobj.name);
+```
+
+### mkstemp like, asynchronously
Creates a new temporary directory with mode `0700` and filename like `/tmp/tmp-nk2J1u`.
@@ -119,7 +203,18 @@ tmp.dir({ template: '/tmp/tmp-XXXXXX' }, function _tempDirCreated(err, path) {
});
```
-### Filename generation
+### mkstemp like, synchronously
+
+This will behave similarly to the asynchronous version.
+
+```javascript
+var tmp = require('tmp');
+
+var tmpobj = tmp.dirSync({ template: '/tmp/tmp-XXXXXX' });
+console.log("Dir: ", tmpobj.name);
+```
+
+### Asynchronous filename generation
The `tmpName()` function accepts the `prefix`, `postfix`, `dir`, etc. parameters also:
@@ -133,6 +228,16 @@ tmp.tmpName({ template: '/tmp/tmp-XXXXXX' }, function _tempNameGenerated(err, pa
});
```
+### Synchronous filename generation
+
+The `tmpNameSync()` function works similarly to `tmpName()`.
+
+```javascript
+var tmp = require('tmp');
+var tmpname = tmp.tmpNameSync({ template: '/tmp/tmp-XXXXXX' });
+console.log("Created temporary filename: ", tmpname);
+```
+
## Graceful cleanup
One may want to cleanup the temporary files even when an uncaught exception
@@ -151,12 +256,13 @@ All options are optional :)
* `mode`: the file mode to create with, it fallbacks to `0600` on file creation and `0700` on directory creation
* `prefix`: the optional prefix, fallbacks to `tmp-` if not provided
* `postfix`: the optional postfix, fallbacks to `.tmp` on file creation
- * `template`: [`mkstemps`][3] like filename template, no default
+ * `template`: [`mkstemp`][3] like filename template, no default
* `dir`: the optional temporary directory, fallbacks to system default (guesses from environment)
* `tries`: how many times should the function try to get a unique filename before giving up, default `3`
* `keep`: signals that the temporary file or directory should not be deleted on exit, default is `false`, means delete
+ * Please keep in mind that it is recommended in this case to call the provided `cleanupCallback` function manually.
* `unsafeCleanup`: recursively removes the created temporary directory, even when it's not empty. default is `false`
[1]: http://nodejs.org/
-[2]: https://github.com/bruce/node-temp
+[2]: https://www.npmjs.com/browse/depended/tmp
[3]: http://www.kernel.org/doc/man-pages/online/pages/man3/mkstemp.3.html
diff --git a/node_modules/tmp/domain-test.js b/node_modules/tmp/domain-test.js
deleted file mode 100644
index 47221bc3f..000000000
--- a/node_modules/tmp/domain-test.js
+++ /dev/null
@@ -1,13 +0,0 @@
-var domain = require('domain');
-
-//throw new Error('bazz');
-
-var d = domain.create();
-d.on('error', function ( e ) {
- console.log('error!!!', e);
-});
-
-d.run(function () {
- console.log('hey');
- throw new Error('bazz');
-});
diff --git a/node_modules/tmp/lib/tmp.js b/node_modules/tmp/lib/tmp.js
index ea84faa55..bb83c7ec3 100644
--- a/node_modules/tmp/lib/tmp.js
+++ b/node_modules/tmp/lib/tmp.js
@@ -1,7 +1,7 @@
/*!
* Tmp
*
- * Copyright (c) 2011-2013 KARASZI Istvan <github@spam.raszi.hu>
+ * Copyright (c) 2011-2015 KARASZI Istvan <github@spam.raszi.hu>
*
* MIT Licensed
*/
@@ -12,10 +12,10 @@
var
fs = require('fs'),
path = require('path'),
- os = require('os'),
- exists = fs.exists || path.exists,
- tmpDir = os.tmpDir || _getTMPDir,
- _c = require('constants');
+ crypto = require('crypto'),
+ tmpDir = require('os-tmpdir'),
+ _c = process.binding('constants');
+
/**
* The working inner variables.
@@ -25,8 +25,16 @@ var
_TMP = tmpDir(),
// the random characters to choose from
- randomChars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz",
- randomCharsLength = randomChars.length,
+ RANDOM_CHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz',
+
+ TEMPLATE_PATTERN = /XXXXXX/,
+
+ DEFAULT_TRIES = 3,
+
+ CREATE_FLAGS = (_c.O_CREAT || _c.fs.O_CREAT) | (_c.O_EXCL || _c.fs.O_EXCL) | (_c.O_RDWR || _c.fs.O_RDWR),
+
+ DIR_MODE = 448 /* 0700 */,
+ FILE_MODE = 384 /* 0600 */,
// this will hold the objects need to be removed on exit
_removeObjects = [],
@@ -35,22 +43,30 @@ var
_uncaughtException = false;
/**
- * Gets the temp directory.
+ * Random name generator based on crypto.
+ * Adapted from http://blog.tompawlak.org/how-to-generate-random-values-nodejs-javascript
*
+ * @param {Number} howMany
* @return {String}
* @api private
*/
-function _getTMPDir() {
- var tmpNames = [ 'TMPDIR', 'TMP', 'TEMP' ];
-
- for (var i = 0, length = tmpNames.length; i < length; i++) {
- if (_isUndefined(process.env[tmpNames[i]])) continue;
+function _randomChars(howMany) {
+ var
+ value = [],
+ rnd = null;
+
+ // make sure that we do not fail because we ran out of entropy
+ try {
+ rnd = crypto.randomBytes(howMany);
+ } catch (e) {
+ rnd = crypto.pseudoRandomBytes(howMany);
+ }
- return process.env[tmpNames[i]];
+ for (var i = 0; i < howMany; i++) {
+ value.push(RANDOM_CHARS[rnd[i] % RANDOM_CHARS.length]);
}
- // fallback to the default
- return '/tmp';
+ return value.join('');
}
/**
@@ -74,19 +90,51 @@ function _isUndefined(obj) {
* @api private
*/
function _parseArguments(options, callback) {
- if (!callback || typeof callback != "function") {
- callback = options;
+ if (typeof options == 'function') {
+ var
+ tmp = options,
+ options = callback || {},
+ callback = tmp;
+ } else if (typeof options == 'undefined') {
options = {};
}
- return [ options, callback ];
+ return [options, callback];
}
/**
- * Gets a temporary file name.
+ * Generates a new temporary name.
*
* @param {Object} opts
- * @param {Function} cb
+ * @returns {String}
+ * @api private
+ */
+function _generateTmpName(opts) {
+ if (opts.name) {
+ return path.join(opts.dir || _TMP, opts.name);
+ }
+
+ // mkstemps like template
+ if (opts.template) {
+ return opts.template.replace(TEMPLATE_PATTERN, _randomChars(6));
+ }
+
+ // prefix and postfix
+ var name = [
+ opts.prefix || 'tmp-',
+ process.pid,
+ _randomChars(12),
+ opts.postfix || ''
+ ].join('');
+
+ return path.join(opts.dir || _TMP, name);
+}
+
+/**
+ * Gets a temporary file name.
+ *
+ * @param {Object} options
+ * @param {Function} callback
* @api private
*/
function _getTmpName(options, callback) {
@@ -94,49 +142,23 @@ function _getTmpName(options, callback) {
args = _parseArguments(options, callback),
opts = args[0],
cb = args[1],
- template = opts.template,
- templateDefined = !_isUndefined(template),
- tries = opts.tries || 3;
+ tries = opts.tries || DEFAULT_TRIES;
if (isNaN(tries) || tries < 0)
return cb(new Error('Invalid tries'));
- if (templateDefined && !template.match(/XXXXXX/))
+ if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
return cb(new Error('Invalid template provided'));
- function _getName() {
-
- // prefix and postfix
- if (!templateDefined) {
- var name = [
- (_isUndefined(opts.prefix)) ? 'tmp-' : opts.prefix,
- process.pid,
- (Math.random() * 0x1000000000).toString(36),
- opts.postfix
- ].join('');
-
- return path.join(opts.dir || _TMP, name);
- }
-
- // mkstemps like template
- var chars = [];
-
- for (var i = 0; i < 6; i++) {
- chars.push(randomChars.substr(Math.floor(Math.random() * randomCharsLength), 1));
- }
-
- return template.replace(/XXXXXX/, chars.join(''));
- }
-
(function _getUniqueName() {
- var name = _getName();
+ var name = _generateTmpName(opts);
// check whether the path exists then retry if needed
- exists(name, function _pathExists(pathExists) {
- if (pathExists) {
+ fs.stat(name, function (err) {
+ if (!err) {
if (tries-- > 0) return _getUniqueName();
- return cb(new Error('Could not get a unique tmp filename, max tries reached'));
+ return cb(new Error('Could not get a unique tmp filename, max tries reached ' + name));
}
cb(null, name);
@@ -145,6 +167,37 @@ function _getTmpName(options, callback) {
}
/**
+ * Synchronous version of _getTmpName.
+ *
+ * @param {Object} options
+ * @returns {String}
+ * @api private
+ */
+function _getTmpNameSync(options) {
+ var
+ args = _parseArguments(options),
+ opts = args[0],
+ tries = opts.tries || DEFAULT_TRIES;
+
+ if (isNaN(tries) || tries < 0)
+ throw new Error('Invalid tries');
+
+ if (opts.template && !opts.template.match(TEMPLATE_PATTERN))
+ throw new Error('Invalid template provided');
+
+ do {
+ var name = _generateTmpName(opts);
+ try {
+ fs.statSync(name);
+ } catch (e) {
+ return name;
+ }
+ } while (tries-- > 0);
+
+ throw new Error('Could not get a unique tmp filename, max tries reached');
+}
+
+/**
* Creates and opens a temporary file.
*
* @param {Object} options
@@ -157,68 +210,80 @@ function _createTmpFile(options, callback) {
opts = args[0],
cb = args[1];
- opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;
+ opts.postfix = (_isUndefined(opts.postfix)) ? '.tmp' : opts.postfix;
// gets a temporary filename
_getTmpName(opts, function _tmpNameCreated(err, name) {
if (err) return cb(err);
// create and open the file
- fs.open(name, _c.O_CREAT | _c.O_EXCL | _c.O_RDWR, opts.mode || 0600, function _fileCreated(err, fd) {
+ fs.open(name, CREATE_FLAGS, opts.mode || FILE_MODE, function _fileCreated(err, fd) {
if (err) return cb(err);
- var removeCallback = _prepareRemoveCallback(fs.unlinkSync.bind(fs), name);
-
- if (!opts.keep) {
- _removeObjects.unshift(removeCallback);
- }
-
- cb(null, name, fd, removeCallback);
+ cb(null, name, fd, _prepareTmpFileRemoveCallback(name, fd, opts));
});
});
}
/**
- * Removes files and folders in a directory recursively.
+ * Synchronous version of _createTmpFile.
*
- * @param {String} dir
+ * @param {Object} options
+ * @returns {Object} object consists of name, fd and removeCallback
+ * @api private
*/
-function _rmdirRecursiveSync(dir) {
- var files = fs.readdirSync(dir);
-
- for (var i = 0, length = files.length; i < length; i++) {
- var file = path.join(dir, files[i]);
- // lstat so we don't recurse into symlinked directories.
- var stat = fs.lstatSync(file);
-
- if (stat.isDirectory()) {
- _rmdirRecursiveSync(file);
- } else {
- fs.unlinkSync(file);
- }
- }
+function _createTmpFileSync(options) {
+ var
+ args = _parseArguments(options),
+ opts = args[0];
- fs.rmdirSync(dir);
+ opts.postfix = opts.postfix || '.tmp';
+
+ var name = _getTmpNameSync(opts);
+ var fd = fs.openSync(name, CREATE_FLAGS, opts.mode || FILE_MODE);
+
+ return {
+ name : name,
+ fd : fd,
+ removeCallback : _prepareTmpFileRemoveCallback(name, fd, opts)
+ };
}
/**
+ * Removes files and folders in a directory recursively.
*
- * @param {Function} removeFunction
- * @param {String} path
- * @returns {Function}
- * @private
+ * @param {String} root
+ * @api private
*/
-function _prepareRemoveCallback(removeFunction, path) {
- var called = false;
- return function() {
- if (called) {
- return;
+function _rmdirRecursiveSync(root) {
+ var dirs = [root];
+
+ do {
+ var
+ dir = dirs.pop(),
+ deferred = false,
+ files = fs.readdirSync(dir);
+
+ for (var i = 0, length = files.length; i < length; i++) {
+ var
+ file = path.join(dir, files[i]),
+ stat = fs.lstatSync(file); // lstat so we don't recurse into symlinked directories
+
+ if (stat.isDirectory()) {
+ if (!deferred) {
+ deferred = true;
+ dirs.push(dir);
+ }
+ dirs.push(file);
+ } else {
+ fs.unlinkSync(file);
+ }
}
- removeFunction(path);
-
- called = true;
- };
+ if (!deferred) {
+ fs.rmdirSync(dir);
+ }
+ } while (dirs.length !== 0);
}
/**
@@ -239,23 +304,109 @@ function _createTmpDir(options, callback) {
if (err) return cb(err);
// create the directory
- fs.mkdir(name, opts.mode || 0700, function _dirCreated(err) {
+ fs.mkdir(name, opts.mode || DIR_MODE, function _dirCreated(err) {
if (err) return cb(err);
- var removeCallback = _prepareRemoveCallback(
- opts.unsafeCleanup
- ? _rmdirRecursiveSync
- : fs.rmdirSync.bind(fs),
- name
- );
+ cb(null, name, _prepareTmpDirRemoveCallback(name, opts));
+ });
+ });
+}
- if (!opts.keep) {
- _removeObjects.unshift(removeCallback);
+/**
+ * Synchronous version of _createTmpDir.
+ *
+ * @param {Object} options
+ * @returns {Object} object consists of name and removeCallback
+ * @api private
+ */
+function _createTmpDirSync(options) {
+ var
+ args = _parseArguments(options),
+ opts = args[0];
+
+ var name = _getTmpNameSync(opts);
+ fs.mkdirSync(name, opts.mode || DIR_MODE);
+
+ return {
+ name : name,
+ removeCallback : _prepareTmpDirRemoveCallback(name, opts)
+ };
+}
+
+/**
+ * Prepares the callback for removal of the temporary file.
+ *
+ * @param {String} name
+ * @param {int} fd
+ * @param {Object} opts
+ * @api private
+ * @returns {Function} the callback
+ */
+function _prepareTmpFileRemoveCallback(name, fd, opts) {
+ var removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
+ try {
+ fs.closeSync(fdPath[0]);
+ }
+ catch (e) {
+ // under some node/windows related circumstances, a temporary file
+ // may have not be created as expected or the file was already closed
+ // by the user, in which case we will simply ignore the error
+ if (e.errno != -(_c.EBADF || _c.os.errno.EBADF) && e.errno != -(_c.ENOENT || _c.os.errno.ENOENT)) {
+ // reraise any unanticipated error
+ throw e;
}
+ }
+ fs.unlinkSync(fdPath[1]);
+ }, [fd, name]);
- cb(null, name, removeCallback);
- });
- });
+ if (!opts.keep) {
+ _removeObjects.unshift(removeCallback);
+ }
+
+ return removeCallback;
+}
+
+/**
+ * Prepares the callback for removal of the temporary directory.
+ *
+ * @param {String} name
+ * @param {Object} opts
+ * @returns {Function} the callback
+ * @api private
+ */
+function _prepareTmpDirRemoveCallback(name, opts) {
+ var removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs.rmdirSync.bind(fs);
+ var removeCallback = _prepareRemoveCallback(removeFunction, name);
+
+ if (!opts.keep) {
+ _removeObjects.unshift(removeCallback);
+ }
+
+ return removeCallback;
+}
+
+/**
+ * Creates a guarded function wrapping the removeFunction call.
+ *
+ * @param {Function} removeFunction
+ * @param {Object} arg
+ * @returns {Function}
+ * @api private
+ */
+function _prepareRemoveCallback(removeFunction, arg) {
+ var called = false;
+
+ return function _cleanupCallback() {
+ if (called) return;
+
+ var index = _removeObjects.indexOf(_cleanupCallback);
+ if (index >= 0) {
+ _removeObjects.splice(index, 1);
+ }
+
+ called = true;
+ removeFunction(arg);
+ };
}
/**
@@ -268,9 +419,11 @@ function _garbageCollector() {
return;
}
- for (var i = 0, length = _removeObjects.length; i < length; i++) {
+ // the function being called removes itself from _removeObjects,
+ // loop until _removeObjects is empty
+ while (_removeObjects.length) {
try {
- _removeObjects[i].call(null);
+ _removeObjects[0].call(null);
} catch (e) {
// already removed?
}
@@ -286,7 +439,7 @@ var version = process.versions.node.split('.').map(function (value) {
});
if (version[0] === 0 && (version[1] < 9 || version[1] === 9 && version[2] < 5)) {
- process.addListener('uncaughtException', function _uncaughtExceptionThrown( err ) {
+ process.addListener('uncaughtException', function _uncaughtExceptionThrown(err) {
_uncaughtException = true;
_garbageCollector();
@@ -302,6 +455,9 @@ process.addListener('exit', function _exit(code) {
// exporting all the needed methods
module.exports.tmpdir = _TMP;
module.exports.dir = _createTmpDir;
+module.exports.dirSync = _createTmpDirSync;
module.exports.file = _createTmpFile;
+module.exports.fileSync = _createTmpFileSync;
module.exports.tmpName = _getTmpName;
+module.exports.tmpNameSync = _getTmpNameSync;
module.exports.setGracefulCleanup = _setGracefulCleanup;
diff --git a/node_modules/tmp/package.json b/node_modules/tmp/package.json
index eeb31274b..71f58092d 100644
--- a/node_modules/tmp/package.json
+++ b/node_modules/tmp/package.json
@@ -1,18 +1,13 @@
{
"name": "tmp",
- "version": "0.0.24",
+ "version": "0.0.30",
"description": "Temporary file and directory creator",
"author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)",
"homepage": "http://github.com/raszi/node-tmp",
"keywords": [ "temporary", "tmp", "temp", "tempdir", "tempfile", "tmpdir", "tmpfile" ],
- "licenses": [
- {
- "type": "MIT",
- "url": "http://opensource.org/licenses/MIT"
- }
- ],
+ "license": "MIT",
"repository": {
"type": "git",
@@ -33,7 +28,9 @@
"node": ">=0.4.0"
},
- "dependencies": {},
+ "dependencies": {
+ "os-tmpdir": "~1.0.1"
+ },
"devDependencies": {
"vows": "~0.7.0"
diff --git a/node_modules/tmp/test-all.sh b/node_modules/tmp/test-all.sh
deleted file mode 100755
index 4734d6056..000000000
--- a/node_modules/tmp/test-all.sh
+++ /dev/null
@@ -1,9 +0,0 @@
-#!/bin/bash
-
-#node06
-for node in node08 node; do
- command -v ${node} > /dev/null 2>&1 || continue
-
- echo "Testing with $(${node} --version)..."
- ${node} node_modules/vows/bin/vows test/*test.js
-done
diff --git a/node_modules/tmp/test.js b/node_modules/tmp/test.js
deleted file mode 100644
index 8058221c4..000000000
--- a/node_modules/tmp/test.js
+++ /dev/null
@@ -1,6 +0,0 @@
-process.on('uncaughtException', function ( err ) {
- console.log('blah');
- throw err;
-});
-
-throw "on purpose"
diff --git a/node_modules/tmp/test/base.js b/node_modules/tmp/test/base.js
index 498d8fb3b..a77f3a566 100644
--- a/node_modules/tmp/test/base.js
+++ b/node_modules/tmp/test/base.js
@@ -1,7 +1,12 @@
var
assert = require('assert'),
path = require('path'),
- exec = require('child_process').exec;
+ exec = require('child_process').exec,
+ tmp = require('../lib/tmp');
+
+// make sure that we do not test spam the global tmp
+tmp.TMP_DIR = './tmp';
+
function _spawnTestWithError(testFile, params, cb) {
_spawnTest(true, testFile, params, cb);
@@ -13,7 +18,6 @@ function _spawnTestWithoutError(testFile, params, cb) {
function _spawnTest(passError, testFile, params, cb) {
var
- filename,
node_path = process.argv[0],
command = [ node_path, path.join(__dirname, testFile) ].concat(params).join(' ');
@@ -37,38 +41,109 @@ function _testStat(stat, mode) {
}
function _testPrefix(prefix) {
- return function _testPrefixGenerated(err, name, fd) {
+ return function _testPrefixGenerated(err, name) {
assert.equal(path.basename(name).slice(0, prefix.length), prefix, 'should have the provided prefix');
};
}
+function _testPrefixSync(prefix) {
+ return function _testPrefixGeneratedSync(result) {
+ if (result instanceof Error) {
+ throw result;
+ }
+ _testPrefix(prefix)(null, result.name, result.fd);
+ };
+}
+
function _testPostfix(postfix) {
- return function _testPostfixGenerated(err, name, fd) {
+ return function _testPostfixGenerated(err, name) {
assert.equal(name.slice(name.length - postfix.length, name.length), postfix, 'should have the provided postfix');
};
}
+function _testPostfixSync(postfix) {
+ return function _testPostfixGeneratedSync(result) {
+ if (result instanceof Error) {
+ throw result;
+ }
+ _testPostfix(postfix)(null, result.name, result.fd);
+ };
+}
+
function _testKeep(type, keep, cb) {
_spawnTestWithError('keep.js', [ type, keep ], cb);
}
+function _testKeepSync(type, keep, cb) {
+ _spawnTestWithError('keep-sync.js', [ type, keep ], cb);
+}
+
function _testGraceful(type, graceful, cb) {
_spawnTestWithoutError('graceful.js', [ type, graceful ], cb);
}
+function _testGracefulSync(type, graceful, cb) {
+ _spawnTestWithoutError('graceful-sync.js', [ type, graceful ], cb);
+}
+
function _assertName(err, name) {
assert.isString(name);
- assert.isNotZero(name.length);
+ assert.isNotZero(name.length, 'an empty string is not a valid name');
+}
+
+function _assertNameSync(result) {
+ if (result instanceof Error) {
+ throw result;
+ }
+ var name = typeof(result) == 'string' ? result : result.name;
+ _assertName(null, name);
+}
+
+function _testName(expected){
+ return function _testNameGenerated(err, name) {
+ assert.equal(expected, name, 'should have the provided name');
+ };
+}
+
+function _testNameSync(expected){
+ return function _testNameGeneratedSync(result) {
+ if (result instanceof Error) {
+ throw result;
+ }
+ _testName(expected)(null, result.name, result.fd);
+ };
}
function _testUnsafeCleanup(unsafe, cb) {
_spawnTestWithoutError('unsafe.js', [ 'dir', unsafe ], cb);
}
+function _testIssue62(cb) {
+ _spawnTestWithoutError('issue62.js', [], cb);
+}
+
+function _testUnsafeCleanupSync(unsafe, cb) {
+ _spawnTestWithoutError('unsafe-sync.js', [ 'dir', unsafe ], cb);
+}
+
+function _testIssue62Sync(cb) {
+ _spawnTestWithoutError('issue62-sync.js', [], cb);
+}
+
module.exports.testStat = _testStat;
module.exports.testPrefix = _testPrefix;
+module.exports.testPrefixSync = _testPrefixSync;
module.exports.testPostfix = _testPostfix;
+module.exports.testPostfixSync = _testPostfixSync;
module.exports.testKeep = _testKeep;
+module.exports.testKeepSync = _testKeepSync;
module.exports.testGraceful = _testGraceful;
+module.exports.testGracefulSync = _testGracefulSync;
module.exports.assertName = _assertName;
+module.exports.assertNameSync = _assertNameSync;
+module.exports.testName = _testName;
+module.exports.testNameSync = _testNameSync;
module.exports.testUnsafeCleanup = _testUnsafeCleanup;
+module.exports.testIssue62 = _testIssue62;
+module.exports.testUnsafeCleanupSync = _testUnsafeCleanupSync;
+module.exports.testIssue62Sync = _testIssue62Sync;
diff --git a/node_modules/tmp/test/dir-test.js b/node_modules/tmp/test/dir-test.js
index 2e4e52999..9f2c282b3 100644
--- a/node_modules/tmp/test/dir-test.js
+++ b/node_modules/tmp/test/dir-test.js
@@ -60,11 +60,22 @@ vows.describe('Directory creation').addBatch({
'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
- 'should be a file': _testDir(040700),
+ 'should be a directory': _testDir(040700),
'should have the provided prefix': Test.testPrefix('clike-'),
'should have the provided postfix': Test.testPostfix('-postfix')
},
+ 'when using name': {
+ topic: function () {
+ tmp.dir({ name: 'using-name' }, this.callback);
+ },
+
+ 'should not return with an error': assert.isNull,
+ 'should return with a name': Test.assertName,
+ 'should be a directory': _testDir(040700),
+ 'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name'))
+ },
+
'when using multiple options': {
topic: function () {
tmp.dir({ prefix: 'foo', postfix: 'bar', mode: 0750 }, this.callback);
@@ -118,7 +129,7 @@ vows.describe('Directory creation').addBatch({
'should not return with error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function (err, name) {
- assert.ok(!existsSync(name), "Directory should be removed");
+ assert.ok(!existsSync(name), 'Directory should be removed');
}
},
@@ -143,7 +154,7 @@ vows.describe('Directory creation').addBatch({
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function (err, name) {
- assert.ok(!existsSync(name), "Directory should be removed");
+ assert.ok(!existsSync(name), 'Directory should be removed');
}
},
@@ -155,7 +166,7 @@ vows.describe('Directory creation').addBatch({
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function (err, name) {
- assert.ok(!existsSync(name), "Directory should be removed");
+ assert.ok(!existsSync(name), 'Directory should be removed');
},
'should remove symlinked dir': function(err, name) {
assert.ok(
@@ -171,6 +182,18 @@ vows.describe('Directory creation').addBatch({
}
},
+ 'unsafeCleanup === true with issue62 structure': {
+ topic: function () {
+ Test.testIssue62(this.callback);
+ },
+
+ 'should not return with an error': assert.isNull,
+ 'should return with a name': Test.assertName,
+ 'should not exist': function (err, name) {
+ assert.ok(!existsSync(name), 'Directory should be removed');
+ }
+ },
+
'unsafeCleanup === false': {
topic: function () {
Test.testUnsafeCleanup('0', this.callback);
@@ -178,7 +201,13 @@ vows.describe('Directory creation').addBatch({
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
- 'should be a directory': _testDir(040700)
+ 'should be a directory': function (err, name) {
+ _testDir(040700)(err, name);
+ // make sure that everything gets cleaned up
+ fs.unlinkSync(path.join(name, 'should-be-removed.file'));
+ fs.unlinkSync(path.join(name, 'symlinkme-target'));
+ fs.rmdirSync(name);
+ }
},
'remove callback': {
@@ -190,7 +219,7 @@ vows.describe('Directory creation').addBatch({
'should return with a name': Test.assertName,
'removeCallback should remove directory': function (_err, name, removeCallback) {
removeCallback();
- assert.ok(!existsSync(name), "Directory should be removed");
+ assert.ok(!existsSync(name), 'Directory should be removed');
}
}
}).exportTo(module);
diff --git a/node_modules/tmp/test/file-test.js b/node_modules/tmp/test/file-test.js
index d9605b38a..b710859c0 100644
--- a/node_modules/tmp/test/file-test.js
+++ b/node_modules/tmp/test/file-test.js
@@ -79,6 +79,20 @@ vows.describe('File creation').addBatch({
'should have the provided postfix': Test.testPostfix('-postfix')
},
+ 'when using name': {
+ topic: function () {
+ tmp.file({ name: 'using-name.tmp' }, this.callback);
+ },
+
+ 'should not return with an error': assert.isNull,
+ 'should return with a name': Test.assertName,
+ 'should have the provided name': Test.testName(path.join(tmp.tmpdir, 'using-name.tmp')),
+ 'should be a file': function (err, name) {
+ _testFile(0100600, true);
+ fs.unlinkSync(name);
+ }
+ },
+
'when using multiple options': {
topic: function () {
tmp.file({ prefix: 'foo', postfix: 'bar', mode: 0640 }, this.callback);
@@ -132,7 +146,7 @@ vows.describe('File creation').addBatch({
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function (err, name) {
- assert.ok(!existsSync(name), "File should be removed");
+ assert.ok(!existsSync(name), 'File should be removed');
}
},
@@ -157,7 +171,7 @@ vows.describe('File creation').addBatch({
'should not return with an error': assert.isNull,
'should return with a name': Test.assertName,
'should not exist': function (err, name) {
- assert.ok(!existsSync(name), "File should be removed");
+ assert.ok(!existsSync(name), 'File should be removed');
}
},
@@ -170,7 +184,7 @@ vows.describe('File creation').addBatch({
'should return with a name': Test.assertName,
'removeCallback should remove file': function (_err, name, _fd, removeCallback) {
removeCallback();
- assert.ok(!existsSync(name), "File should be removed");
+ assert.ok(!existsSync(name), 'File should be removed');
}
}
diff --git a/node_modules/tmp/test/graceful.js b/node_modules/tmp/test/graceful.js
index c898656f3..dbe554e1c 100644
--- a/node_modules/tmp/test/graceful.js
+++ b/node_modules/tmp/test/graceful.js
@@ -10,6 +10,6 @@ if (graceful) {
spawn.tmpFunction(function (err, name) {
spawn.out(name, function () {
- throw new Error("Thrown on purpose");
+ throw new Error('Thrown on purpose');
});
});