Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #230: regression after fix for #197 #231

Merged
merged 1 commit into from
Jan 29, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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