Comparing version 0.0.23 to 0.0.24
@@ -170,5 +170,9 @@ /*! | ||
if (!opts.keep) _removeObjects.unshift([ fs.unlinkSync, name ]); | ||
var removeCallback = _prepareRemoveCallback(fs.unlinkSync.bind(fs), name); | ||
cb(null, name, fd); | ||
if (!opts.keep) { | ||
_removeObjects.unshift(removeCallback); | ||
} | ||
cb(null, name, fd, removeCallback); | ||
}); | ||
@@ -181,3 +185,3 @@ }); | ||
* | ||
* @param {String} path | ||
* @param {String} dir | ||
*/ | ||
@@ -203,2 +207,22 @@ function _rmdirRecursiveSync(dir) { | ||
/** | ||
* | ||
* @param {Function} removeFunction | ||
* @param {String} path | ||
* @returns {Function} | ||
* @private | ||
*/ | ||
function _prepareRemoveCallback(removeFunction, path) { | ||
var called = false; | ||
return function() { | ||
if (called) { | ||
return; | ||
} | ||
removeFunction(path); | ||
called = true; | ||
}; | ||
} | ||
/** | ||
* Creates a temporary directory. | ||
@@ -224,11 +248,14 @@ * | ||
var removeCallback = _prepareRemoveCallback( | ||
opts.unsafeCleanup | ||
? _rmdirRecursiveSync | ||
: fs.rmdirSync.bind(fs), | ||
name | ||
); | ||
if (!opts.keep) { | ||
if (opts.unsafeCleanup) { | ||
_removeObjects.unshift([ _rmdirRecursiveSync, name ]); | ||
} else { | ||
_removeObjects.unshift([ fs.rmdirSync, name ]); | ||
} | ||
_removeObjects.unshift(removeCallback); | ||
} | ||
cb(null, name); | ||
cb(null, name, removeCallback); | ||
}); | ||
@@ -250,3 +277,3 @@ }); | ||
try { | ||
_removeObjects[i][0].call(null, _removeObjects[i][1]); | ||
_removeObjects[i].call(null); | ||
} catch (e) { | ||
@@ -253,0 +280,0 @@ // already removed? |
{ | ||
"name": "tmp", | ||
"version": "0.0.23", | ||
"version": "0.0.24", | ||
"description": "Temporary file and directory creator", | ||
@@ -5,0 +5,0 @@ "author": "KARASZI István <github@spam.raszi.hu> (http://raszi.hu/)", |
@@ -182,3 +182,16 @@ var | ||
'should be a directory': _testDir(040700) | ||
}, | ||
'remove callback': { | ||
topic: function () { | ||
tmp.dir(this.callback); | ||
}, | ||
'should not return with an error': assert.isNull, | ||
'should return with a name': Test.assertName, | ||
'removeCallback should remove directory': function (_err, name, removeCallback) { | ||
removeCallback(); | ||
assert.ok(!existsSync(name), "Directory should be removed"); | ||
} | ||
} | ||
}).exportTo(module); |
@@ -68,3 +68,2 @@ var | ||
'should have the provided postfix': Test.testPostfix('.txt') | ||
}, | ||
@@ -164,4 +163,17 @@ | ||
} | ||
}, | ||
'remove callback': { | ||
topic: function () { | ||
tmp.file(this.callback); | ||
}, | ||
'should not return with an error': assert.isNull, | ||
'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"); | ||
} | ||
} | ||
}).exportTo(module); |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29424
771