Commit f85cc05b authored by Ross Gammon's avatar Ross Gammon

Imported Upstream version 0.0.27

parent 5d354007
......@@ -6,10 +6,8 @@ A simple temporary file and directory creator for [node.js.][1]
## 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.
Tmp offers both an asynchronous and a synchronous API. For all API calls, all
the parameters are optional.
......@@ -264,5 +262,5 @@ All options are optional :)
* `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
......@@ -343,7 +343,18 @@ function _createTmpDirSync(options) {
*/
function _prepareTmpFileRemoveCallback(name, fd, opts) {
var removeCallback = _prepareRemoveCallback(function _removeCallback(fdPath) {
fs.closeSync(fdPath[0]);
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 && e.errno != -c.ENOENT) {
// reraise any unanticipated error
throw e;
}
}
fs.unlinkSync(fdPath[1]);
}, [fd, name]);
......@@ -363,12 +374,8 @@ function _prepareTmpFileRemoveCallback(name, fd, opts) {
* @returns {Function} the callback
*/
function _prepareTmpDirRemoveCallback(name, opts) {
var removeCallback = _prepareRemoveCallback(
opts.unsafeCleanup
? _rmdirRecursiveSync
: fs.rmdirSync.bind(fs),
name);
var removeFunction = opts.unsafeCleanup ? _rmdirRecursiveSync : fs.rmdirSync.bind(fs);
var removeCallback = _prepareRemoveCallback(removeFunction, name);
if (!opts.keep) {
_removeObjects.unshift(removeCallback);
......
{
"name": "tmp",
"version": "0.0.26",
"version": "0.0.27",
"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",
......
......@@ -189,7 +189,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': {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment