Deleting a tree of folders using rimraf can be pretty fraught on MS Windows; the OS itself can lock files randomly, and there may be various processes getting in the way, like virus checkers or cloud file syncing apps. rimraf
itself will do an exponential-backoff-and-retry for EBUSY
and ENOTEMPTY
errors on Windows, but you can still see EPERM
and others. If you want to do exponential-backoff-and-retry for any error, see the below recipe, using node-retry.
Last active
February 19, 2016 16:29
-
-
Save n3dst4/d6b1ee7744d706e6f80b to your computer and use it in GitHub Desktop.
Using node-retry to work around errors in Windows when using rimraf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var rimraf = require("rimraf"); | |
var retry = require("retry"); | |
function safeRimraf (path, cb) { | |
var operation = retry.operation(); | |
operation.attempt(function(currentAttempt) { | |
rimraf(path, function (err) { | |
if (operation.retry(err? true : null)) { | |
return; | |
} | |
cb(err ? operation.mainError() : null); | |
}); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment