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: simplify copy operations and more cleanups #31038

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

BridgeAR
Copy link
Member

This is just a minor refactoring to reduce the code overhead.

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

@nodejs-github-bot nodejs-github-bot added the fs Issues and PRs related to the fs subsystem / file system. label Dec 20, 2019
lib/internal/fs/promises.js Outdated Show resolved Hide resolved
@nodejs-github-bot

This comment has been minimized.

@nodejs-github-bot
Copy link
Collaborator

@BridgeAR BridgeAR added the semver-major PRs that contain breaking changes and should be released in the next major version. label Dec 26, 2019
@BridgeAR
Copy link
Member Author

I noticed late that there's actually a test added in #635 that checks that inherited properties are checked as well as fs option (this will likely not work everywhere but at least in streams).

I decided to remove the failing test. I think it's a good idea not to fall back to the prototype but this seems to be a breaking change.
To all who gave their LGs: please take another look and confirm that.

@Trott
Copy link
Member

Trott commented Dec 27, 2019

@nodejs/fs

@Trott
Copy link
Member

Trott commented Dec 27, 2019

@Trott Trott added author ready PRs that have at least one approval, no pending requests for changes, and a CI started. and removed author ready PRs that have at least one approval, no pending requests for changes, and a CI started. labels Dec 28, 2019
@Trott
Copy link
Member

Trott commented Dec 28, 2019

Removing the author ready label I added as I realize that since it has surfaced that this is a breaking change, some of the LGTMs should be reiterated (especially from @nodejs/tsc folks).

This is mainly a minor refactoring to reduce the code overhead with
the side effect of removing support for prototype properties in
passed through options.
Copying options is mostly done for enumerable own properties and
prototype properties are ignored.
@BridgeAR
Copy link
Member Author

BridgeAR commented Jan 12, 2020

Rebased due to conflicts.

@jasnell @devnexen @lpinca this is semver-major, which was not known while you gave your LG. It would be great if you could confirm/update your LG.

@nodejs-github-bot
Copy link
Collaborator

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I‘m not sure I understand the breaking change. Can you please articulate it further? What would break?

@BridgeAR
Copy link
Member Author

@mcollina inherited object properties won't be accepted as options anymore. So if you do e.g.: Object.create({ encoding: 'utf8' }), encoding won't be detected anymore and it's just handled as empty object instead.

Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think doing a breaking change for a refactoring is worth it in this case.

@BridgeAR
Copy link
Member Author

@mcollina the question is if we want to officially support inherited properties or not. I was quite surprised when I noticed the failure that we allowed something like that. AFAIK we do not have any guarantees of supporting inherited properties in any other API. We partially prevent this actively to prevent attacks based on prototype pollution and there are open PRs to do this even more: #30008 and #30063.

I guess it might be a good for the @nodejs/tsc to weight in if we want to generically support inherited properties or if we should instead actively recommend against relying on any prototype properties while passing through options. I am fine to close this if others want to keep the current behavior.

// cc @watson

@mcollina
Copy link
Member

I'm happy with the change as long as it is clearly spelled out and it's a direction we would like the project to go.

@BridgeAR BridgeAR force-pushed the master branch 2 times, most recently from 8ae28ff to 2935f72 Compare May 31, 2020 12:19
@jasnell jasnell added the stalled Issues and PRs that are stalled. label Jun 25, 2020
@lundibundi
Copy link
Member

ping @BridgeAR @mcollina should this be added to tsc-agenda then?

@mcollina
Copy link
Member

mcollina commented Sep 3, 2020

@lundibundi everybody can add the tsc-agenda tag. May I ask to formulate a question to the tsc when you do so? Are you asking for a vote on this?

My take on the -1 is on the breakage for the sake of a refactoring, which is the description of this PR.

@lundibundi
Copy link
Member

I think the question would be (only partially related to this PR):
Should the inherited properties be checked and supported in options object throughout the Node.js APIs? (i.e. fs currently supports fs.createReadStream(rangeFile, Object.create({ autoClose: false }));, fs.createReadStream(fn, Object.create({ encoding: 'utf8' }));, while http.request(Object.create({ ... }), res => {}) will ignore properties in options)

AFAIK none of our APIs provide any explicit guarantees of supporting inherited properties in options object. Quickly looking through our code some of the APIs which don't need to store options object, like EventEmitter support this because they just check for them via options.a. At the same time http.createServer, http.get, http.request, child_process APIs use { ...options } which doesn't take inherited properties into account.

@BridgeAR could you please clarify if the above is correct? (feel free to just edit this comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
blocked PRs that are blocked by other issues or PRs. fs Issues and PRs related to the fs subsystem / file system. semver-major PRs that contain breaking changes and should be released in the next major version. stalled Issues and PRs that are stalled.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants