GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fs/promises: ensure options.flag is defaulted to 'r' in readFile by bdistin · Pull Request #20268 · nodejs/node

Conversation

@bdistin

@bdistin bdistin commented Apr 24, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

When passing {} or { encoding: 'utf8' } as options to readFile, the
flag is not defaulted to 'r' unlike normal fs. This fix makes
(fs/promises).readFile() act consistently with fs.readFile().

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • commit message follows commit guidelines

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

kyranet, Excigma, and benjamingr reacted with thumbs up emoji
All reactions
  • 👍 3 reactions
@Trott

Trott commented Apr 24, 2018

Copy link
Copy Markdown
Member

@nodejs/fs

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Trott Trott added the fs Issues and PRs related to file-system APIs and the fs module. label Apr 24, 2018
@vsemozhetbyt vsemozhetbyt added the promises Issues and PRs related to ECMAScript promises. label Apr 24, 2018
@bdistin
bdistin force-pushed the fix-readfile-flag-default branch from 76a8dbb to 58b874d Compare April 25, 2018 01:22
@ronkorving

ronkorving commented Apr 25, 2018

Copy link
Copy Markdown
Contributor

I'm curious if the behavior of getOptions is as intended. Can someone shed some light on this? Should we not merge these default options into a given object?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

BridgeAR
BridgeAR reviewed Apr 25, 2018
View reviewed changes
Comment thread lib/fs/promises.js Outdated

@BridgeAR BridgeAR Apr 25, 2018

Copy link
Copy Markdown
Member

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 will actually manipulate the passed in options because getOptions does not copy the options object.
Please do:

if (options.flag == null) {
  options = copyObject(options);
  options.flag = 'r';
}

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@BridgeAR

BridgeAR commented Apr 25, 2018

Copy link
Copy Markdown
Member

@ronkorving you are right in a way: the getOptions changed in a way that breaks with the former behavior. I am looking into that.

benjamingr and ronkorving reacted with thumbs up emoji
All reactions
  • 👍 2 reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin
bdistin force-pushed the fix-readfile-flag-default branch from 58b874d to c64b578 Compare April 29, 2018 21:44
@bdistin

bdistin commented Apr 29, 2018

Copy link
Copy Markdown
Contributor Author

No longer manipulates the passed in options. Since options.flag is not needed in readFileHandle(), copied the existing style from writeFile() instead of null check + copyObject().

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@apapirovski

apapirovski commented May 3, 2018

Copy link
Copy Markdown
Contributor

@nodejs/fs Please have a look at this PR.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

jasnell
jasnell approved these changes May 3, 2018
View reviewed changes
ronkorving
ronkorving approved these changes May 7, 2018
View reviewed changes
trivikr
trivikr approved these changes May 7, 2018
View reviewed changes
@ChALkeR ChALkeR added the experimental Issues and PRs related to experimental features. label May 8, 2018
@bdistin

bdistin commented May 9, 2018

Copy link
Copy Markdown
Contributor Author

I see that the fs/promises API has been moved to fs.promises, causing conflicts in this pr. Should I resolve those conflicts? (This is my first pr to Node, so I am still a bit unsure of the processes expected.)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@trivikr

trivikr commented May 9, 2018

Copy link
Copy Markdown
Member

@bdistin Yes, please update this PR by following instructions in Step 9

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin
bdistin force-pushed the fix-readfile-flag-default branch 4 times, most recently from 3e0d004 to f5a462f Compare May 9, 2018 16:48
@bdistin
fs/promises: ensure options.flag is defaulted to 'r' in readFile
f5a462f
When passing {} or { encoding: 'utf8' } as options to readFile, the
flag is not defaulted to 'r' unlike normal fs. This fix makes
(fs/promises).readFile() act consistently with fs.readFile().
@bdistin

bdistin commented May 9, 2018

Copy link
Copy Markdown
Contributor Author

Also given the changes of the fs/promises paradigm, should the pr/commit be named just fs: instead of fs/promises:?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@vsemozhetbyt

vsemozhetbyt commented May 9, 2018

Copy link
Copy Markdown
Contributor

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin

bdistin commented May 14, 2018

Copy link
Copy Markdown
Contributor Author

Is there anything more I need to do? I can't explain how the Windows 2016 binary tests fail, and can't see how that would be related to the changes made in this pr. If this is something I need to fix, can anyone shed light on what changes I might need to make?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bzoz

bzoz commented May 14, 2018

Copy link
Copy Markdown
Contributor

Windows CI rerun: https://ci.nodejs.org/job/node-test-commit-windows-fanned/17969/

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin

bdistin commented May 16, 2018

Copy link
Copy Markdown
Contributor Author

So that CI seemed to have passed, but the checks weren't updated on this pr. Does that mean this is good to go?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin

bdistin commented May 26, 2018

Copy link
Copy Markdown
Contributor Author

bump? @nodejs/fs ??

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joyeecheung
joyeecheung approved these changes May 26, 2018
View reviewed changes

@joyeecheung joyeecheung left a comment

Copy link
Copy Markdown
Member

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 would've expected that getOptions should extend fields of the options if they are not present..but the current fix works as well.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@joyeecheung

joyeecheung commented May 26, 2018

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label May 26, 2018
@joyeecheung joyeecheung added dont-land-on-v6.x labels May 26, 2018
joyeecheung
joyeecheung previously requested changes May 27, 2018
View reviewed changes
Comment thread test/parallel/test-fs-promises-readfile-empty.js
const { promises: fs } = require('fs');
const fixtures = require('../common/fixtures');

const fn = fixtures.path('empty.txt');

This comment was marked as resolved.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@joyeecheung joyeecheung removed the author ready PRs with CI started, the required approvals, and no outstanding review comments. label May 27, 2018
@bdistin
test: requested change
26bce85
fail on unhandled rejection
@joyeecheung
joyeecheung dismissed their stale review May 27, 2018 15:32

fixed

@joyeecheung

joyeecheung commented May 27, 2018

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin
test: fix requested change
ca44fc2
common was required, but not assigned to common in order for the requested change to work.
@joyeecheung

joyeecheung commented May 27, 2018

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin

bdistin commented May 27, 2018 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

It seems with the test fixes, the tests have uncovered another bug: https://github.com/nodejs/node/blob/master/lib/internal/fs/promises.js#L140-L141
Specifically, readFileHandle() ignores the encoding option when the size of the file to read is 0 and returns a buffer instead of an empty string.

How should I handle that bug? Should I increase the scope of this pr to fix that bug as well?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

joyeecheung
joyeecheung reviewed May 28, 2018
View reviewed changes
Comment thread test/parallel/test-fs-promises-readfile-empty.js
.then(assert.ok);

fs.readFile(fn, 'utf8')
.then(assert.strictEqual.bind(this, ''));

This comment was marked as resolved.

Sign in to view

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@bdistin
fs: return string on empty fs.promises.readFile() when encoding provided
543f297
fs: return string on empty fs.promises.readfile when encoding provided

fs.promises.readfile() would provide a buffer whenever an empty file
is read, when it should have returned an empty string when encoding
is provided.
BridgeAR
BridgeAR approved these changes May 29, 2018
View reviewed changes
@BridgeAR

BridgeAR commented May 29, 2018

Copy link
Copy Markdown
Member

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

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR added the author ready PRs with CI started, the required approvals, and no outstanding review comments. label May 29, 2018
@BridgeAR

BridgeAR commented May 30, 2018

Copy link
Copy Markdown
Member

Landed in 2cd3e61 🎉

pedall reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@BridgeAR BridgeAR closed this May 30, 2018
BridgeAR pushed a commit to BridgeAR/node that referenced this pull request May 30, 2018
@bdistin @BridgeAR
fs: ensure options.flag defaults to 'r' in readFile
2cd3e61
When passing {} or { encoding: 'utf8' } as options to readFile, the
flag is not defaulted to 'r' unlike normal fs. This fix makes
fs.promises.readFile() act consistent with fs.readFile().

It also fixes another issue with fs.promises.readfile() where it
returned a Buffer instead of an empty string when encoding is provided.

PR-URL: nodejs#20268
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ron Korving <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
addaleax pushed a commit that referenced this pull request May 31, 2018
@bdistin @addaleax
fs: ensure options.flag defaults to 'r' in readFile
44ef458
When passing {} or { encoding: 'utf8' } as options to readFile, the
flag is not defaulted to 'r' unlike normal fs. This fix makes
fs.promises.readFile() act consistent with fs.readFile().

It also fixes another issue with fs.promises.readfile() where it
returned a Buffer instead of an empty string when encoding is provided.

PR-URL: #20268
Reviewed-By: James M Snell <[email protected]>
Reviewed-By: Ron Korving <[email protected]>
Reviewed-By: Trivikram Kamat <[email protected]>
Reviewed-By: Ruben Bridgewater <[email protected]>
@MylesBorins MylesBorins mentioned this pull request Jun 6, 2018
v10.4.0 proposal #21167
Merged
@richardlau richardlau mentioned this pull request Jan 10, 2019
fs.promises API is working but why #25435
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@joyeecheung joyeecheung joyeecheung left review comments
@jasnell jasnell jasnell approved these changes
@BridgeAR BridgeAR BridgeAR approved these changes
@trivikr trivikr trivikr approved these changes
+1 more reviewer
@ronkorving ronkorving ronkorving approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

author ready PRs with CI started, the required approvals, and no outstanding review comments. experimental Issues and PRs related to experimental features. fs Issues and PRs related to file-system APIs and the fs module. promises Issues and PRs related to ECMAScript promises.

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

11 participants

@bdistin @Trott @ronkorving @BridgeAR @apapirovski @trivikr @vsemozhetbyt @bzoz @joyeecheung @jasnell @ChALkeR
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.