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.watch(): EINVAL on Windows watching a root file #4643

Closed
bpasero opened this issue Jan 12, 2016 · 7 comments · Fixed by #5994
Closed

fs.watch(): EINVAL on Windows watching a root file #4643

bpasero opened this issue Jan 12, 2016 · 7 comments · Fixed by #5994
Labels
fs Issues and PRs related to the fs subsystem / file system. libuv Issues and PRs related to the libuv dependency or the uv binding. windows Issues and PRs related to the Windows platform.

Comments

@bpasero
Copy link
Contributor

bpasero commented Jan 12, 2016

node.js: 4.2.1
OS: Win10

  • have a file test.txt directly on C:
  • try to watch it: fs.watch("C:\\test.txt")

=>

> fs.watch("C:\\test.txt")
Error: watch C:\test.txt EINVAL
    at exports._errnoException (util.js:874:11)
    at FSWatcher.start (fs.js:1239:19)
    at Object.fs.watch (fs.js:1267:11)
    at repl:1:4
    at REPLServer.defaultEval (repl.js:164:27)
    at bound (domain.js:280:14)
    at REPLServer.runBound [as eval] (domain.js:293:12)
    at REPLServer.<anonymous> (repl.js:393:12)
    at emitOne (events.js:82:20)
    at REPLServer.emit (events.js:169:7)
@mscdex mscdex added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Jan 12, 2016
@mscdex
Copy link
Contributor

mscdex commented Jan 12, 2016

/cc @nodejs/platform-windows

@jorangreef
Copy link
Contributor

When watching files, I think libuv actually creates a watch on the parent directory of the file (https://github.com/libuv/libuv/blob/v1.x/src/win/fs-event.c#L188), in this case C:\\. Could that have something to do with it? Also, do you have appropriate permissions to access C:\\?

@bpasero
Copy link
Contributor Author

bpasero commented Jan 12, 2016

Yes, otherwise you will get an EPERM

@orangemocha
Copy link
Contributor

This looks like a bug in libuv. If the file is at the root, and we try split the path into a directory name and file name (https://github.com/libuv/libuv/blob/f1a13e9b4abe8c97768a1d38b12ca3766c8a9b34/src/win/fs-event.c#L198-L206), we end up with a directory name that doesn't have a trailing backslash, e.g. \\?\C:. When passing that to CreateFile() Windows thinks we are trying to open the drive rather than the root directory. Adding a trailing backslash fixes the issue.

I'll add this to my queue of fixes. If anyone else wants to open a PR to https://github.com/libuv/libuv, you are welcome to do so. Thanks for reporting this issue!

@CxRes
Copy link

CxRes commented Mar 22, 2016

@saghul @seishun Has this change been upstreamed? I still have this problem with node 5.9.0.

@saghul
Copy link
Member

saghul commented Mar 23, 2016

@CxRes It's part of libuv but not yet of any release. It will be part of the next one, which should happen by Node 6.0.

@CxRes
Copy link

CxRes commented Mar 23, 2016

@saghul Thanks!

@ChALkeR ChALkeR added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Apr 1, 2016
saghul added a commit to saghul/node that referenced this issue Apr 7, 2016
saghul added a commit that referenced this issue Apr 7, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Apr 19, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
saghul added a commit to saghul/node that referenced this issue Jul 11, 2016
Fixes: nodejs#5737
Fixes: nodejs#4643
Fixes: nodejs#4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: nodejs#3594
PR-URL: nodejs#5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Jul 11, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Jul 11, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Jul 12, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Jul 14, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
MylesBorins pushed a commit that referenced this issue Jul 14, 2016
Fixes: #5737
Fixes: #4643
Fixes: #4291
Fixes: nodejs/node-v0.x-archive#8960
Refs: #3594
PR-URL: #5994
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system. libuv Issues and PRs related to the libuv dependency or the uv binding. windows Issues and PRs related to the Windows platform.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants