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.readFile does not account file system flag 'a+' in Node 14.11 #35290

Closed
O4epegb opened this issue Sep 22, 2020 · 5 comments
Closed

fs.readFile does not account file system flag 'a+' in Node 14.11 #35290

O4epegb opened this issue Sep 22, 2020 · 5 comments
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.

Comments

@O4epegb
Copy link

O4epegb commented Sep 22, 2020

I tried to find similar issues but couldn't, sorry if it is already reported.

  • Version:
    v14.11.0
  • Platform:
    Darwin MacBook-Pro-Daniil.local 18.7.0 Darwin Kernel Version 18.7.0: Thu Jun 20 18:42:21 PDT 2019; root:xnu-4903.270.47~4/RELEASE_X86_64 x86_64

What steps will reproduce the bug?

With a+ flag file should be created if it does not exist. It works with readFileSync, but fails with readFile
There is also similar problem with w+ flag and maybe others, but I did not tested all of them.

const fs = require('fs');

const content = fs.readFileSync('./nonexistingfile1', {
  encoding: 'utf-8',
  flag: 'a+',
});

console.log(content); // content is empty string, so file was created

fs.readFile(
  './nonexistingfile2',
  { encoding: 'utf-8', flag: 'a+' },
  (err, data) => {
    console.log(err, data);
    // [Error: ENOENT: no such file or directory, open './nonexistingfile2'] {
    //   errno: -2,
    //   code: 'ENOENT',
    //   syscall: 'open',
    //   path: './nonexistingfile2'
    // }
  }
);

How often does it reproduce? Is there a required condition?

Always with node v14.11
Works fine in node v12.18.4

What is the expected behavior?

File is created before reading and there is no ENOENT error

What do you see instead?

ENOENT error

    [Error: ENOENT: no such file or directory, open './nonexistingfile2'] {
      errno: -2,
      code: 'ENOENT',
      syscall: 'open',
      path: './nonexistingfile2'
    }
@watilde watilde added the fs Issues and PRs related to the fs subsystem / file system. label Sep 22, 2020
@O4epegb
Copy link
Author

O4epegb commented Sep 22, 2020

I am not sure, since I'm new to Node source codebase, but it might be connected to this PR https://github.com/nodejs/node/pull/27044/files#diff-9a205ef7ee967ee32efee02e58b3482dL314

Possible typo since there is no such thing as options.flags only options.flag.

I have no idea how to test it yet, but I can make PR if this is the problem

@BridgeAR BridgeAR added confirmed-bug Issues with confirmed bugs. regression Issues related to regressions. labels Sep 22, 2020
@BridgeAR
Copy link
Member

@O4epegb a PR would be great. This seems to be a typo.

@O4epegb
Copy link
Author

O4epegb commented Sep 22, 2020

Ok, I'll make it soon!

@targos
Copy link
Member

targos commented Sep 22, 2020

This issue made me realize that we have a big inconsistency regarding this option: all methods expect it to be flag in the options object, except the stream ones (createReadStream, createWriteStream), which look for the flags property...

@O4epegb O4epegb changed the title fs.readFile not account for file system flag 'a+' in Node 14.11 fs.readFile does not account file system flag 'a+' in Node 14.11 Sep 22, 2020
@O4epegb
Copy link
Author

O4epegb commented Oct 19, 2020

I guess this issue could be closed now?

Fixed here: #35292

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
confirmed-bug Issues with confirmed bugs. fs Issues and PRs related to the fs subsystem / file system. regression Issues related to regressions.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants