-
-
Notifications
You must be signed in to change notification settings - Fork 35.4k
fs: add rm method #35494
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
Changes from 1 commit
9845d05
6c26d17
f0f37b1
b1fa541
641bc3b
adbc955
7aca540
384a7e9
1876684
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -52,6 +52,7 @@ const { | |
| validateBufferArray, | ||
| validateOffsetLengthRead, | ||
| validateOffsetLengthWrite, | ||
| validateRmOptionsSync, | ||
| validateRmdirOptions, | ||
| validateStringAfterArrayBufferView, | ||
| warnOnNonPortableTemplate | ||
|
|
@@ -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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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);
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
|
|
||
| return rimrafPromises(path, options); | ||
| } | ||
|
|
||
| async function rmdir(path, options) { | ||
| path = pathModule.toNamespacedPath(getValidatedPath(path)); | ||
| options = validateRmdirOptions(options); | ||
|
|
@@ -635,6 +643,7 @@ module.exports = { | |
| opendir: promisify(opendir), | ||
| rename, | ||
| truncate, | ||
| rm, | ||
| rmdir, | ||
| mkdir, | ||
| readdir, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -5,8 +5,8 @@ const fs = require('fs'); | |
| const path = require('path'); | ||
| const { isMainThread } = require('worker_threads'); | ||
|
|
||
| function rimrafSync(pathname) { | ||
| fs.rmdirSync(pathname, { maxRetries: 3, recursive: true }); | ||
| function rmSync(pathname) { | ||
| fs.rmSync(pathname, { maxRetries: 3, recursive: true, force: true }); | ||
| } | ||
|
|
||
| const testRoot = process.env.NODE_TEST_DIR ? | ||
|
|
@@ -20,7 +20,7 @@ const tmpPath = path.join(testRoot, tmpdirName); | |
|
|
||
| let firstRefresh = true; | ||
| function refresh() { | ||
| rimrafSync(this.path); | ||
| rmSync(this.path); | ||
| fs.mkdirSync(this.path); | ||
|
|
||
| if (firstRefresh) { | ||
|
|
@@ -37,7 +37,7 @@ function onexit() { | |
| process.chdir(testRoot); | ||
|
|
||
| try { | ||
| rimrafSync(tmpPath); | ||
| rmSync(tmpPath); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. love it 😄 |
||
| } catch (e) { | ||
| console.error('Can\'t clean tmpdir:', tmpPath); | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.