-
Notifications
You must be signed in to change notification settings - Fork 29.6k
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 rm method #35494
fs: add rm method #35494
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just a small amount of initial review. I'll leave more through review, once a few more folks have chimed in.
@@ -37,7 +37,7 @@ function onexit() { | |||
process.chdir(testRoot); | |||
|
|||
try { | |||
rimrafSync(tmpPath); | |||
rmSync(tmpPath); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
love it 😄
lib/internal/fs/promises.js
Outdated
@@ -417,6 +418,13 @@ async function ftruncate(handle, len = 0) { | |||
return binding.ftruncate(handle.fd, len, kUsePromises); | |||
} | |||
|
|||
async function rm(path, options) { | |||
path = pathModule.toNamespacedPath(getValidatedPath(path)); | |||
options = validateRmOptionsSync(path, options); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should use the async validation here, otherwise we're going to create a bottleneck when performing many rm
operations, you can do something like this:
options = await new Promise((resolve, reject) => {
validateRmOptionsSync(path, options, false, (err, options) => {
if (err) return reject(err);
else return resolve(options);
});
})
return rimrafPromises(path, options);
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't this still creating the same bottleneck tho, it's just deferring the result? a new Promise
executor runs synchronously.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ljharb my bad, I meant:
options = await new Promise((resolve, reject) => {
validateRmOptions(path, options, false, (err, options) => {
if (err) return reject(err);
else return resolve(options);
});
})
return rimrafPromises(path, options);
i.e., not using the sync
version of the validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This hasn't been updated yet, but yes, @bcoe's updated suggestion would address my point. I'd also say that it's worth adding a custom promisify implementation to validateRmOptions
, and then use await promisify(validateRmOptions)(path, options, false)
instead?
Two points:
|
@CxRes I'm pretty confused at this point, @iansu is matching the behavior of the method
If the issue is that we're not actually using a binding to an os level |
@bcoe going back to the TSC points... 2 said we would set up a function that |
@CxRes Point 2 from the TSC plan is already done. This PR is point number 4. |
@CxRes this is an interpretation of the suggestions from the TSC meeting, that I believe could be a good approach: 1) Let's mark the current API as stable, since it's used a lot This work has been done here. 2. Rename the current API to e.g., This PR introduces the method Since we have opted to use the
I like that using the analogy 3. The alias gets deprecated This PR prints a deprecation warning if you attempt to use 4. Add a new function that has the stricter version I am advocating that rather than adding another "stricter" method, we will make the existing This will bring the behavior of the existing |
OK! This, I guess, was the source of my confusion. I was interpreting this as a new method all along! My only question in that case is: Do you really want to bring back the deprecated Edit: Never mind that, I read @bcoe's comment on the other thread. I understand what you are doing now. Thanks for taking all this trouble!!! |
@CxRes the argument I'd make for keeping the stricter flag, is that there'd be less userland breakage (and platforms like The balance is between breaking existing users, vs., best possible design. I'm in the camp that, given there's prior art on other platforms of the stricter form of Edit: @CxRes I have to admit too, I now find myself getting excited about ideas like an interactive |
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a documentation related nit (it might be good to mention force only suppresses some types of errors).
Other than that, I'd just like to get a few more opinions on where we've chosen to include the deprecation warning -- make sure other folks are 👍 to keeping the strict form of recursive
on rmdir
.
CC: @nodejs/fs , @nodejs/tsc, @nodejs/tooling for review (making sure this is in the spirit of our conversation.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I believe tests should start passing once you merge these suggestions.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
CI: https://ci.nodejs.org/job/node-test-pull-request/33477/ ✅ ☝️ tests are green. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM as what I believe we agreed to in the TSC discussions and since it looks like Matteo's suggestions have been addressed.
I would like to merge this later this afternoon ideally, given the tight timeline (unless folks come in with major concerns of course.). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
This PR introduces a new method fs.rm that provides the behaviour of rimraf when used with the recursive: true and force: true options. PR-URL: #35494 Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Landed in 4e9f3cc |
This PR introduces a new method fs.rm that provides the behaviour of rimraf when used with the recursive: true and force: true options. PR-URL: #35494 Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Notable changes: crypto: * update certdata to NSS 3.56 (Shelley Vohr) #35546 doc: * add aduh95 to collaborators (Antoine du Hamel) #35542 fs: * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494 http: * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274 src: * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512 PR-URL: TODO
This is a follow up to #35494 to add a deprecation warning when using recursive rmdir. This only warns if you are attempting to remove a file or a nonexistent path. PR-URL: #35562 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Notable changes: crypto: * update certdata to NSS 3.56 (Shelley Vohr) #35546 doc: * add aduh95 to collaborators (Antoine du Hamel) #35542 fs: * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494 http: * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274 src: * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512 PR-URL: TODO
Notable changes: crypto: * update certdata to NSS 3.56 (Shelley Vohr) #35546 doc: * add aduh95 to collaborators (Antoine du Hamel) #35542 fs: * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494 http: * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274 src: * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512 PR-URL: #35648
Notable changes: crypto: * update certdata to NSS 3.56 (Shelley Vohr) #35546 doc: * add aduh95 to collaborators (Antoine du Hamel) #35542 fs: * (SEMVER-MINOR) add rm method (Ian Sutherland) #35494 http: * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) #35274 src: * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) #35512 PR-URL: #35648
Hi there, sorry but I have a couple of questions about the
|
@rait there's also a conversation on this topic here (it's probably better to discuss on an open issue). This option was carried over from rimraf.js, when @iansu @Trott it feels like, if nothing else, we need to better document the motivation of this retry, and explain its origin. |
This PR introduces a new method fs.rm that provides the behaviour of rimraf when used with the recursive: true and force: true options. PR-URL: nodejs#35494 Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ruy Adorno <ruyadorno@github.com> Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
This is a follow up to nodejs#35494 to add a deprecation warning when using recursive rmdir. This only warns if you are attempting to remove a file or a nonexistent path. PR-URL: nodejs#35562 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com> Reviewed-By: Ben Coe <bencoe@gmail.com> Reviewed-By: Michael Dawson <midawson@redhat.com>
Has this been tested on windows ? |
@GrosSacASac Yes, it has been tested on Windows. This functionality was previously in Node.js for about a year under the |
Notable changes: crypto: * update certdata to NSS 3.56 (Shelley Vohr) nodejs/node#35546 doc: * add aduh95 to collaborators (Antoine du Hamel) nodejs/node#35542 fs: * (SEMVER-MINOR) add rm method (Ian Sutherland) nodejs/node#35494 http: * (SEMVER-MINOR) allow passing array of key/val into writeHead (Robert Nagy) nodejs/node#35274 src: * (SEMVER-MINOR) expose v8::Isolate setup callbacks (Shelley Vohr) nodejs/node#35512 PR-URL: nodejs/node#35648
Based on the decision by the TSC in their October 1st meeting I'm opening this PR and closing my previous PR #35250 which kicked off this discussion. You can see a summary of the plan the TSC agreed on in this comment: #35250 (comment)
This PR introduces a new method
fs.rm
that provides the behaviour ofrimraf
when used with therecursive: true
andforce: true
options. It also adds a deprecation warning when usingfs.rmdir
withrecursive: true
only if the path is a file or does not exist. This functionality has also been deprecated in the docs: #35171The behaviour of this new
fs.rm
method follows that of the UNIXrm
command. The exact behaviour is explained in this table:Checklist
make -j4 test
(UNIX), orvcbuild test
(Windows) passes