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 file matching is one character off in windows #4351

Closed
jsheely opened this issue Dec 19, 2015 · 8 comments
Closed

fs.watch file matching is one character off in windows #4351

jsheely opened this issue Dec 19, 2015 · 8 comments
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

@jsheely
Copy link

jsheely commented Dec 19, 2015

var fs = require('fs');

fs.watch('test/file.jsx', {}, (event, filename) => {
    console.log('Changed file', filename);
});
  • Changes to a file file.js will yield change events for file.jsx
  • Changes to file file.j will yield changes events file.js

Note: Tested on Windows 10

@jsheely jsheely changed the title File matching is one character off in windows fs.watch file matching is one character off in windows Dec 19, 2015
@ChALkeR ChALkeR added fs Issues and PRs related to the fs subsystem / file system. windows Issues and PRs related to the Windows platform. labels Dec 19, 2015
@mdolbin
Copy link

mdolbin commented Dec 22, 2015

@jsheely Seems like it matches any file if its name starts the same as the one we're watching for.
For example, each of the following actions was reported as Changed file file.jsx:
(Assume we have file.jsx, file.js, file.j, bad-name.txt at the same folder)

  • Create empty file file or f or ...
  • Rename file to f or file.j to fil or bad-name.txt to fi or ...
  • Edit f or fil or file.j or file.js or ...
  • Remove f or fil or ...

Editing and renaming triggers callback twice, unless 'matching' filename was renamed to something that doesn't match file.jsx anymore or 'matching' file was deleted - these are reported once.

Reproduced on (Virtualbox)

  • Windows x64 7 Ultimate SP 1
  • Node v4.2.3 & v5.3.0 - one at a time

Not reproduced on

  • OSX Yosemite 10.10.5 (14F1021) (macbook)
  • Node v4.1.1(homebrew) & v5.3.0 (homebrew) - one at a time

@GenuineRex
Copy link

The watching functions in Windows watch directories not files. I do not see anything inside node or uv that checks for the specified file to be the file that triggered the change. Node documentation says that fs.watch relies on ReadDirectoryChangesW which is watching a directory not a specific file. Try fs.watchFIle instead.

@jsheely
Copy link
Author

jsheely commented Dec 26, 2015

@GenuineRex True it does watch directories but it also knows what file was changed. The problem is that the libuv abstraction returns the closest file that matches the pattern being watched currently and not the actual full path to the file that was changed.

However the real file name is available that was modified and can be sent out to the event loop. I have tracked down the bug to here. #4429

Note: That this still fires a change event for a file in the directory but libraries will now be capable of filtering them out as the pattern won't match a file they are watching.

@GenuineRex
Copy link

I see it now.

@ChALkeR ChALkeR added the libuv Issues and PRs related to the libuv dependency or the uv binding. label Dec 26, 2015
@jasnell
Copy link
Member

jasnell commented Apr 9, 2016

@saghul @bnoordhuis

@bnoordhuis
Copy link
Member

Libuv 1.9 has a number of Windows file watcher fixes. I don't know when you plan on releasing the next v5, but there's a good chance it fixes this issue.

@wc-matteo
Copy link

Another issue probably related: nodejs/node-v0.x-archive#25689

@jasongin
Copy link
Member

This is fixed by libuv/libuv#682. There has not yet been a libuv release containing the fix: it came after the last libuv release, v1.9.1.

cjihrig added a commit to cjihrig/node that referenced this issue Oct 26, 2016
Fixes: nodejs#4351
Fixes: nodejs#6763
Refs: nodejs#8280
PR-URL: nodejs#9267
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
evanlucas pushed a commit that referenced this issue Nov 3, 2016
Fixes: #4351
Fixes: #6763
Refs: #8280
PR-URL: #9267
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue May 16, 2017
Fixes: #4351
Fixes: #6763
Refs: #8280
PR-URL: #9267
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
MylesBorins pushed a commit that referenced this issue May 18, 2017
Fixes: #4351
Fixes: #6763
Refs: #8280
PR-URL: #9267
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
andrew749 pushed a commit to michielbaird/node that referenced this issue Jul 19, 2017
Fixes: nodejs/node#4351
Fixes: nodejs/node#6763
Refs: nodejs/node#8280
PR-URL: nodejs/node#9267
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: James M Snell <jasnell@gmail.com>
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

No branches or pull requests

8 participants