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.access() not reporting error on Windows #19192

Closed
dougwit opened this issue Mar 7, 2018 · 10 comments
Closed

fs.access() not reporting error on Windows #19192

dougwit opened this issue Mar 7, 2018 · 10 comments
Labels
doc Issues and PRs related to the documentations. fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform.

Comments

@dougwit
Copy link

dougwit commented Mar 7, 2018

  • Version: 9.6.1
  • Platform: Windows 7 Professional x64
  • Subsystem: fs

fs.access() returns no error when given a file/directory with no priveleges.

Code example:

'use strict'

const fs = require('fs')

fs.access('./restricted', fs.constants.R_OK || fs.constants.W_OK, err => {
  if (err) {
    console.log(err)
  } else {
    console.log('no access() error')
  }
})

fs.stat('./restricted', (err, stat) => {
  if (err) {
    console.log(err)
  } else {
    console.log('no stat() error')
  }
})

Output:

no access() error
{ Error: EPERM: operation not permitted
  errno: -4048,
  code: 'EPERM',
  syscall: 'stat',
  path: 'C:\\Workspaces\\restricted' }
@vsemozhetbyt vsemozhetbyt added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Mar 7, 2018
@joyeecheung
Copy link
Member

See #7700 , fs.access does not check ACL on Windows

@joyeecheung
Copy link
Member

Setting a doc label because the documentation seems to be misleading:

fs.constants.R_OK - path can be read by the calling process.
fs.constants.W_OK - path can be written by the calling process.

@joyeecheung joyeecheung added the doc Issues and PRs related to the documentations. label Mar 7, 2018
@joyeecheung
Copy link
Member

Also cc @bnoordhuis is that a wont-fix on Windows?

@bzoz
Copy link
Contributor

bzoz commented Mar 8, 2018

This can be probably fixed in libuv, there is AccessCheck function in WinAPI that seems to do just that. For now lets just document this.

@bnoordhuis
Copy link
Member

This can be probably fixed in libuv

I don't know if we should (but I also don't know if we shouldn't); we don't check ACLs on other platforms.

@dougwit
Copy link
Author

dougwit commented Mar 8, 2018

Not all platforms use ACLs as their native permissions mechanism. Ignoring ACLs makes fs.access() essentially useless on Windows, and the function fails to do what it says it does:

Tests a user's permissions for the file or directory specified by path.

@bnoordhuis
Copy link
Member

Determining whether an ACL applies is a Hard Problem on many platforms. Doing it on one platform but not others makes it inconsistent. You're welcome to open a pull request but I expect other collaborators will raise the same concern.

@dlong500
Copy link

I agree that this behavior makes fs.access useless on Windows except for simply checking that a file/folder exists at all.

As far as consistency is concerned, things are already inconsistent in behavior if fs.access works as designed on one platform but not on another, so I don't see anything wrong with implementing platform-specific internals to create more consistency in the API behavior.

jasnell added a commit to jasnell/node that referenced this issue Oct 19, 2018
targos pushed a commit that referenced this issue Oct 24, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
MylesBorins pushed a commit that referenced this issue Nov 26, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
MylesBorins pushed a commit that referenced this issue Nov 26, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
rvagg pushed a commit that referenced this issue Nov 28, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
MylesBorins pushed a commit that referenced this issue Nov 29, 2018
Fixes: #19192

PR-URL: #23772
Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Bartosz Sosnowski <bartosz@janeasystems.com>
@suchakraborty
Copy link

suchakraborty commented Jun 10, 2020

Actually in 10.15.3 LTS, it does NOTHING, not even file existence check. I dont even have a D drive on my machine, and C:\dev does exist.

PS C:\Users\sc> node -e "const fs = require('fs'); fs.access('D:\\afsd', (err) => {console.log(``${err} is the error.``)})"
 is the error.
PS C:\Users\sc> node -e "const fs = require('fs'); fs.access('C:\\dev', (err) => {console.log(``${err} is the error.``)})"
 is the error.

@stelladraco27
Copy link

I am having this exact issue. I am reading a directory's contents into an array, and getting the stat for each item. I attempted to use fs.access to filter out un-readable folders/files but it would not throw an error. I ended up using the error fs.stat provides to do my filtering. A janky solution, don't like it.

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

No branches or pull requests

8 participants