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: promises fixes #20407

Merged
merged 2 commits into from
May 8, 2018
Merged

fs: promises fixes #20407

merged 2 commits into from
May 8, 2018

Conversation

ChALkeR
Copy link
Member

@ChALkeR ChALkeR commented Apr 29, 2018

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

This fixes two errors in fs/promises:

  1. Removes the leftovers from write(fd, string[, position[, encoding]], callback) signature arg-shifting to find callback — that variable was unused and that logic was corrupting encoding.
  2. chown should do chown, not chmod.

Sorry, this doesn't include tests — I would appreciate some help there. In general, fs/promises test coverage is poor, and this PR isn't aimed at that (yet). Also, #19811 aims to increase the test covereage for fs/promises.

Perhaps #20406 need to be resolved first — the first patch fixes technically undocumented behavior and I am not sure we should be testing it or removing it.

@ChALkeR ChALkeR added the fs Issues and PRs related to the fs subsystem / file system. label Apr 29, 2018
@@ -402,7 +393,7 @@ async function lchown(path, uid, gid) {
if (O_SYMLINK !== undefined) {
const fd = await open(path,
O_WRONLY | O_SYMLINK);
return fchmod(fd, uid, gid).finally(fd.close.bind(fd));
return fchown(fd, uid, gid).finally(fd.close.bind(fd));
Copy link
Contributor

Choose a reason for hiding this comment

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

Is it possible to add a test for this?

Copy link
Member Author

@ChALkeR ChALkeR Apr 29, 2018

Choose a reason for hiding this comment

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

@mscdex In general, fs/promises has poor coverage and this is not the only method that lacks it completely. In the current state, I view that as a separate task. I mentioned that in the PR.

This is not some edge case — the whole public method (among with several others) completely lacks tests and they need to be written.

Ref: https://coverage.nodejs.org/coverage-b55a11d1b17b3e4b/root/fs/promises.js.html

@vsemozhetbyt vsemozhetbyt added the promises Issues and PRs related to ECMAScript promises. label Apr 29, 2018
Copy link
Contributor

@davisjam davisjam left a comment

Choose a reason for hiding this comment

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

Nice catch on fchmod vs fchown.

I think it's appropriate to improve things as you go along, so I think adding a TC for lchown would be good as part of this PR.

@benjamingr
Copy link
Member

I think it's appropriate to improve things as you go along, so I think adding a TC for lchown would be good as part of this PR.

I don't think it's fair to require this here (requesting is fine though) as this PR is an improvement and a bug fix as is. Plus tests for it could be great for a code & learn.

@ChALkeR
Copy link
Member Author

ChALkeR commented Apr 30, 2018

@davisjam @mscdex I opened issue #20435 for tests.
Writing tests for the whole module is out of scope of this PR which is a simple fix.

If there were tests present and this fixed a corner case, I would have included a test for that corner case, but there are just no tests for those functions at all currently (and testing just the patched one won't even improve the situation much).

E.g. #20435 (comment) could be a good approach, but again — out of scope here.
Note how that comment (which I did not predict) demonstrates that the lack of tests should be discussed separately.

@davisjam
Copy link
Contributor

@ChALkeR Clearly I overestimated the state of tests. I retract my objection.

@mscdex
Copy link
Contributor

mscdex commented Apr 30, 2018

I don't understand why tests have to be added separately? I was under the impression that bug fixes should generally come with test(s) to ensure the bug doesn't happen again? To be clear, I wasn't asking for tests for the entire set of fs/promise APIs, just the one being affected in this PR.

@ChALkeR
Copy link
Member Author

ChALkeR commented May 1, 2018

@mscdex @devsnek Because in the current state, that's a separate problem, meaning that it requires more work and discussion than a mere fix here. E.g. #20439 is a good way to address it.

@ChALkeR
Copy link
Member Author

ChALkeR commented May 6, 2018

@mscdex @devsnek @BridgeAR Are there objections to landing this as it is now and dealing with the tests separately?

@BridgeAR
Copy link
Member

BridgeAR commented May 6, 2018

I personally think it would still be best to land it with tests. I know we work on getting something else going but until then, the extra test would help.

Nevertheless, I am not going to block this without a test either. So if it is only about me: go ahead and land it.

@ChALkeR
Copy link
Member Author

ChALkeR commented May 6, 2018

I am going to merge this as it is tomorrow if there would be no explicit concerns.

I still strongly believe that lack of tests for fs/promises should be adressed separately and attemptiing to adress that issue here would just provide a defective result.

@ChALkeR ChALkeR added the experimental Issues and PRs related to experimental features. label May 8, 2018
@ChALkeR
Copy link
Member Author

ChALkeR commented May 8, 2018

@ChALkeR
Copy link
Member Author

ChALkeR commented May 8, 2018

stringbytes-external-exceed-max failures on osx look unrelated.

That code expects the last argument to be a callback.
When it's not a callback, it shifts arguments, defaulting
encoding to 'utf-8', which is clearly broken.

Old signature: (fd, string[, position[, encoding]], callback)
New signature: (fd, string[, position[, encoding]])

PR-URL: nodejs#20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
This was a clear error.

chown should do chown, not chmod.

PR-URL: nodejs#20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@ChALkeR
Copy link
Member Author

ChALkeR commented May 8, 2018

Landed in dd03709...15f7431.

@ChALkeR ChALkeR merged commit 15f7431 into nodejs:master May 8, 2018
MylesBorins pushed a commit that referenced this pull request May 8, 2018
That code expects the last argument to be a callback.
When it's not a callback, it shifts arguments, defaulting
encoding to 'utf-8', which is clearly broken.

Old signature: (fd, string[, position[, encoding]], callback)
New signature: (fd, string[, position[, encoding]])

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 8, 2018
This was a clear error.

chown should do chown, not chmod.

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
@MylesBorins MylesBorins mentioned this pull request May 8, 2018
MylesBorins pushed a commit that referenced this pull request May 8, 2018
That code expects the last argument to be a callback.
When it's not a callback, it shifts arguments, defaulting
encoding to 'utf-8', which is clearly broken.

Old signature: (fd, string[, position[, encoding]], callback)
New signature: (fd, string[, position[, encoding]])

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 8, 2018
This was a clear error.

chown should do chown, not chmod.

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 9, 2018
That code expects the last argument to be a callback.
When it's not a callback, it shifts arguments, defaulting
encoding to 'utf-8', which is clearly broken.

Old signature: (fd, string[, position[, encoding]], callback)
New signature: (fd, string[, position[, encoding]])

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
MylesBorins pushed a commit that referenced this pull request May 9, 2018
This was a clear error.

chown should do chown, not chmod.

PR-URL: #20407
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com>
Reviewed-By: Tiancheng "Timothy" Gu <timothygu99@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Jamie Davis <davisjam@vt.edu>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experimental Issues and PRs related to experimental features. fs Issues and PRs related to the fs subsystem / file system. promises Issues and PRs related to ECMAScript promises.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

10 participants