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

fs: add recursive option to rmdir() #29168

Closed
wants to merge 3 commits into from

Conversation

@cjihrig
Copy link
Contributor

commented Aug 16, 2019

This PR adds a recursive option to fs.rmdir(), fs.rmdirSync(), and fs.promises.rmdir(). The implementation is a port of the npm module rimraf. I added an option to rmdir() to match the approach taken with core's recursive mkdir().

This is my alternative to #28208 from #28208 (review).

I'm marking this PR as a work in progress, as I haven't added docs yet.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
@bcoe bcoe referenced this pull request Aug 17, 2019
4 of 4 tasks complete
@Trott

This comment has been minimized.

Copy link
Member

commented Aug 18, 2019

FWIW, other than the docs and tests that need to be added, this looks good to me.

@silverwind

This comment has been minimized.

Copy link
Contributor

commented Aug 19, 2019

Liking this as well, good call with the lazy loading. Waiting for docs/tests as well. Maybe some of the edge cases like the Windows ones can be included in the tests as well, but it's not a strict requirement.

@cjihrig cjihrig force-pushed the cjihrig:rimraf branch 2 times, most recently from 97b7a02 to e293b5d Aug 19, 2019

@cjihrig cjihrig marked this pull request as ready for review Aug 19, 2019

@cjihrig

This comment has been minimized.

Copy link
Contributor Author

commented Aug 19, 2019

OK, this is ready for review.

It occurred to me that we may want to mark this as experimental for a few releases. Any thoughts?

@nodejs-github-bot

This comment has been minimized.

doc/api/fs.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
doc/api/fs.md Outdated Show resolved Hide resolved
@nodejs-github-bot

This comment has been minimized.

@cjihrig cjihrig force-pushed the cjihrig:rimraf branch from 2a2fbd8 to 28dab64 Aug 20, 2019

@nodejs-github-bot

This comment has been minimized.

Copy link

commented Aug 20, 2019

@bcoe
bcoe approved these changes Aug 20, 2019
Copy link
Member

left a comment

Having thought about rimraf way too much over the last few months, I ultimately come around to liking the consistency that a recursive option introduces (in relation to our implementation of mkdir recursive)...

I think there's meat to the argument that this makes rmdir with an option combine both unlink and rmdir behavior, which is a bit weird, but I feel this is ultimately the better user experience.

doc/api/fs.md Show resolved Hide resolved
lib/internal/fs/rimraf.js Outdated Show resolved Hide resolved
lib/internal/fs/rimraf.js Show resolved Hide resolved
test/parallel/test-fs-rmdir-recursive.js Show resolved Hide resolved
lib/internal/fs/rimraf.js Outdated Show resolved Hide resolved
@Trott

This comment has been minimized.

Copy link
Member

commented Aug 20, 2019

We need to update license-builder.sh and re-run it?

@cjihrig cjihrig force-pushed the cjihrig:rimraf branch from a93476b to a46d568 Aug 20, 2019

@Trott
Trott approved these changes Aug 20, 2019
@cjihrig cjihrig referenced this pull request Aug 20, 2019
3 of 3 tasks complete
@nodejs-github-bot

This comment has been minimized.

@cjihrig cjihrig force-pushed the cjihrig:rimraf branch from a46d568 to 6523fed Aug 21, 2019

@nodejs-github-bot

This comment has been minimized.

Copy link

commented Aug 21, 2019

CI: https://ci.nodejs.org/job/node-test-pull-request/25144/

EDIT: Only failures are ARM 12+ infra issues.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot

This comment has been minimized.

Copy link

commented Aug 22, 2019

cjihrig added 3 commits Aug 16, 2019
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.

@cjihrig cjihrig force-pushed the cjihrig:rimraf branch from 6523fed to ee63d32 Aug 23, 2019

@nodejs-github-bot

This comment has been minimized.

Trott added a commit that referenced this pull request Aug 23, 2019
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: #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>
@Trott

This comment has been minimized.

Copy link
Member

commented Aug 23, 2019

Landed in 53816cc

@Trott Trott closed this Aug 23, 2019

@cjihrig cjihrig deleted the cjihrig:rimraf branch Aug 23, 2019

@iansu iansu referenced this pull request Aug 23, 2019
2 of 5 tasks complete
@ljharb

This comment has been minimized.

Copy link
Member

commented Aug 24, 2019

Sorry i missed the PR; nobody posted a comment in #28208 indicating this one was opened.

Does this mean that to feature detect this option, i have to try/catch around passing the wrong type of options object into the sync function? Am i missing a less invasive mechanism?

@Trott

This comment has been minimized.

Copy link
Member

commented Aug 24, 2019

Sorry i missed the PR; nobody posted a comment in #28208 indicating this one was opened.

Does this mean that to feature detect this option, i have to try/catch around passing the wrong type of options object into the sync function? Am i missing a less invasive mechanism?

Correct. It's the same with the recursive option for mkdir(). We had a lot of discussion around feature detection for that, but when it came down to it, people either didn't need feature detection, kept using the mkdirp package, or did sniffing on process.version/process.versions.node . Not everyone was thrilled about version sniffing but no solution was going to make everyone happy (as the rest of that issue thread and others make clear) and it seems to be working out OK.

BridgeAR added a commit that referenced this pull request Sep 3, 2019
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: #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>
@BridgeAR BridgeAR referenced this pull request Sep 3, 2019
BridgeAR added a commit that referenced this pull request Sep 3, 2019
2019-09-04, Version 12.10.0 (Current)
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
BridgeAR added a commit that referenced this pull request Sep 4, 2019
2019-09-04, Version 12.10.0 (Current)
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
BridgeAR added a commit that referenced this pull request Sep 4, 2019
2019-09-04, Version 12.10.0 (Current)
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    #29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    #29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    #29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    #21387
* net:
  * Allow reading data into a static buffer (Brian White)
    #25436

PR-URL: #29429
@mysticatea

This comment has been minimized.

Copy link

commented Sep 4, 2019

Does this mean that to feature detect this option, i have to try/catch around passing the wrong type of options object into the sync function?

I guess fs.rmdirSync.length can be used to detect because the number of arguments was changed.

JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
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: nodejs#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>
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
2019-09-04, Version 12.10.0 (Current)
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    nodejs#29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    nodejs#29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    nodejs#29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    nodejs#21387
* net:
  * Allow reading data into a static buffer (Brian White)
    nodejs#25436

PR-URL: nodejs#29429
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
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: nodejs#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>
JeniaBR added a commit to JeniaBR/node that referenced this pull request Sep 11, 2019
2019-09-04, Version 12.10.0 (Current)
Notable changes:

* deps:
  * Update npm to 6.10.3 (isaacs)
    nodejs#29023
* fs:
  * Add recursive option to rmdir() (cjihrig)
    nodejs#29168
  * Allow passing true to emitClose option (Giorgos Ntemiris)
    nodejs#29212
  * Add \*timeNs properties to BigInt Stats objects (Joyee Cheung)
    nodejs#21387
* net:
  * Allow reading data into a static buffer (Brian White)
    nodejs#25436

PR-URL: nodejs#29429
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.