Skip to content

Commit

Permalink
Merge pull request #231 from raszi/gh-230
Browse files Browse the repository at this point in the history
fix #230: regression after fix for #197
  • Loading branch information
silkentrance committed Jan 29, 2020
2 parents 562b8f7 + 3aba7d8 commit 61f9a7d
Showing 1 changed file with 5 additions and 29 deletions.
34 changes: 5 additions & 29 deletions lib/tmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ const
_removeObjects = [],

// API change in fs.rmdirSync leads to error when passing in a second parameter, e.g. the callback
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs);
FN_RMDIR_SYNC = fs.rmdirSync.bind(fs),
FN_RIMRAF_SYNC = rimraf.sync;

var
_gracefulCleanup = false;
Expand Down Expand Up @@ -432,31 +433,6 @@ function _prepareTmpFileRemoveCallback(name, fd, opts, sync) {
return sync ? removeCallbackSync : removeCallback;
}

/**
* Simple wrapper for rimraf.
*
* @param {string} dirPath
* @param {Function} next
* @private
*/
function _rimrafRemoveDirWrapper(dirPath, next) {
rimraf(dirPath, next);
}

/**
* Simple wrapper for rimraf.sync.
*
* @param {string} dirPath
* @private
*/
function _rimrafRemoveDirSyncWrapper(dirPath, next) {
try {
return next(null, rimraf.sync(dirPath));
} catch (err) {
return next(err);
}
}

/**
* Prepares the callback for removal of the temporary directory.
*
Expand All @@ -470,8 +446,8 @@ function _rimrafRemoveDirSyncWrapper(dirPath, next) {
* @private
*/
function _prepareTmpDirRemoveCallback(name, opts, sync) {
const removeFunction = opts.unsafeCleanup ? _rimrafRemoveDirWrapper : fs.rmdir.bind(fs);
const removeFunctionSync = opts.unsafeCleanup ? _rimrafRemoveDirSyncWrapper : FN_RMDIR_SYNC;
const removeFunction = opts.unsafeCleanup ? rimraf : fs.rmdir.bind(fs);
const removeFunctionSync = opts.unsafeCleanup ? FN_RIMRAF_SYNC : FN_RMDIR_SYNC;
const removeCallbackSync = _prepareRemoveCallback(removeFunctionSync, name, sync);
const removeCallback = _prepareRemoveCallback(removeFunction, name, sync, removeCallbackSync);
if (!opts.keep) _removeObjects.unshift(removeCallbackSync);
Expand Down Expand Up @@ -507,7 +483,7 @@ function _prepareRemoveCallback(removeFunction, fileOrDirName, sync, cleanupCall
if (index >= 0) _removeObjects.splice(index, 1);

called = true;
if (sync || removeFunction === FN_RMDIR_SYNC) {
if (sync || removeFunction === FN_RMDIR_SYNC || removeFunction == FN_RIMRAF_SYNC) {
return removeFunction(fileOrDirName);
} else {
return removeFunction(fileOrDirName, next || function() {});
Expand Down

0 comments on commit 61f9a7d

Please sign in to comment.