diff options
author | cjihrig <cjihrig@gmail.com> | 2019-08-16 13:17:21 -0400 |
---|---|---|
committer | Rich Trott <rtrott@gmail.com> | 2019-08-23 13:59:07 -0700 |
commit | 53816cce699d02fb28a49b258e1fbc474568bbf8 (patch) | |
tree | b022ff51ac6aa0b0a55cc1a34241eb118d5c0f3a /lib/internal/fs/utils.js | |
parent | 2b1bcba385af380e3eaffd44315c83d3c0201cfe (diff) | |
download | android-node-v8-53816cce699d02fb28a49b258e1fbc474568bbf8.tar.gz android-node-v8-53816cce699d02fb28a49b258e1fbc474568bbf8.tar.bz2 android-node-v8-53816cce699d02fb28a49b258e1fbc474568bbf8.zip |
fs: add recursive option to rmdir()
This commit adds a recursive option to fs.rmdir(),
fs.rmdirSync(), and fs.promises.rmdir(). The implementation
is a port of the npm module rimraf.
PR-URL: https://github.com/nodejs/node/pull/29168
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Roman Reiss <me@silverwind.io>
Reviewed-By: Ben Coe <bencoe@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Jiawen Geng <technicalcute@gmail.com>
Diffstat (limited to 'lib/internal/fs/utils.js')
-rw-r--r-- | lib/internal/fs/utils.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/internal/fs/utils.js b/lib/internal/fs/utils.js index 600d118db3..fb060d23e6 100644 --- a/lib/internal/fs/utils.js +++ b/lib/internal/fs/utils.js @@ -22,6 +22,10 @@ const { } = require('internal/util/types'); const { once } = require('internal/util'); const { toPathIfFileURL } = require('internal/url'); +const { + validateInt32, + validateUint32 +} = require('internal/validators'); const pathModule = require('path'); const kType = Symbol('type'); const kStats = Symbol('stats'); @@ -525,6 +529,30 @@ function warnOnNonPortableTemplate(template) { } } +const defaultRmdirOptions = { + emfileWait: 1000, + maxBusyTries: 3, + recursive: false, +}; + +const validateRmdirOptions = hideStackFrames((options) => { + if (options === undefined) + return defaultRmdirOptions; + if (options === null || typeof options !== 'object') + throw new ERR_INVALID_ARG_TYPE('options', 'object', options); + + options = { ...defaultRmdirOptions, ...options }; + + if (typeof options.recursive !== 'boolean') + throw new ERR_INVALID_ARG_TYPE('recursive', 'boolean', options.recursive); + + validateInt32(options.emfileWait, 'emfileWait', 0); + validateUint32(options.maxBusyTries, 'maxBusyTries'); + + return options; +}); + + module.exports = { assertEncoding, BigIntStats, // for testing @@ -545,5 +573,6 @@ module.exports = { validateOffsetLengthRead, validateOffsetLengthWrite, validatePath, + validateRmdirOptions, warnOnNonPortableTemplate }; |