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

writeFile creates OS inaccessible file #33829

Closed
gnonio opened this issue Jun 10, 2020 · 4 comments
Closed

writeFile creates OS inaccessible file #33829

gnonio opened this issue Jun 10, 2020 · 4 comments
Labels
windows Issues and PRs related to the Windows platform.

Comments

@gnonio
Copy link

gnonio commented Jun 10, 2020

  • Version: v12.16.2
  • Platform: Windows 8.1 64-bit
  • Subsystem:

What steps will reproduce the bug?

`var fs = require('fs')

fs.writeFileSync( "AUX.txt", "test", function(err){return console.log(err)} )

console.log( fs.readFileSync( "AUX.txt", {encoding: 'utf-8'}) )`

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

Always given the provided path "AUX.txt", independently of extension given (tested: "txt" / "js" / null), using another name does not fail.

What is the expected behavior?

A file normally accessible via the OS

What do you see instead?

  • Opening the file with a generic text application fails (notepad++ and notepad)
    notepad++:
    "\\.\AUX" cannot be opened
    "\\." doesn't exist
    notepad:
    Cannot find the \\.\AUX.txt file
  • OS fails to delete or rename file

Additional information

  • creating the file using an absolute path results in same behaviour
  • fs.writeFile async method fails in the same way
  • node does access file contents in the basic test provided
@lundibundi
Copy link
Member

Could you provide full paths of files you are trying to access?
Are you opening the file via default file manager under the same user that run the file-creation script?
Could you be writing file in a different location than you expect (this fs.writeFileSync( "AUX.txt", will write the file in the directory where the script is invoked)?

Also, fs.writeFileSync( "AUX.txt", "test", function(err){return console.log(err)} ) this function doesn't have a callback (the 3rd argument is an options object).

To be clear writeFile creates OS inaccessible file - is an impossible situation because the OS is who actually creates the file and makes any modifications to it, the Node.js (via libuv to be specific) just makes calls (syscall) to the OS to perform those actions.

@gnonio
Copy link
Author

gnonio commented Jun 10, 2020

Much appreciated for your help. You are correct, this has nothing to do with node itself, my apologies.

As it turns out "AUX" is one of many reserved filenames* on this OS.

CON, PRN, AUX, NUL, COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, and LPT9

Given your last hint I attempted to create a file with the same name "AUX.txt" via the OS itself and it fails with the reserved filename explanation. Somehow node must access a deeper api bypassing the restriction, both for writing and reading.

I was caught off guard here. I was generating filenames dynamically for some output and only the AUX.txt file was giving me trouble. I figured the issue had to be deeper than my code, I just did not expect it to be as deep as the OS. Thanks again.

This should probably be closed.

@lundibundi
Copy link
Member

I was not aware of such a requirement on Windows, glad you solved your issue.

Perhaps we can handle this better on Windows so ping @nodejs/platform-windows @nodejs/libuv to give your opinion if this is actionable somehow.

@lundibundi lundibundi added the windows Issues and PRs related to the Windows platform. label Jun 10, 2020
@bzoz
Copy link
Contributor

bzoz commented Jun 10, 2020

Node uses file namespace paths for file access. We do that so we do not get hit by the 260 path limit, but as a side effect, you can create files with reserved names.

Those files are accessible, the app you are using just must support it. You can try opening the file with \\.\[absolute path to the file].

Anyway, there is nothing for Node to fix here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

No branches or pull requests

3 participants