-
-
Notifications
You must be signed in to change notification settings - Fork 581
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
Chokidar will trigger for unmodified files on Windows when LastAccessTime is changed #750
Comments
I can confirm that this is happening on Mac too. I wrote this script to try to work out what's going on: const childProcess = require('child_process')
const chokidar = require('chokidar')
const fs = require('fs-extra')
async function run() {
await fs.unlink('file')
await fs.writeFile('file', 'content')
setTimeout(() => {
const watcher = chokidar.watch('file', {
// we need the stat
alwaysStat: true,
// doesn't do it
// ignore(path, stat) {
// return (stat.atimeMs > stat.mtimeMs)
// },
ignoreInitial: true,
})
let changes = 0
watcher.on('change', (file, stat = {}) => {
// this does it
if (stat.atimeMs > stat.mtimeMs) return
changes++
})
watcher.on('ready', async () => {
setTimeout(() => childProcess.spawnSync('open', ['file']), 250)
setTimeout(() => fs.writeFile('file', 'more content'), 1500)
setTimeout(() => {
watcher.close()
console.log('registered one change', changes === 1)
}, 3000)
})
}, 1000)
}
run() We can bail on Is this something that chokidar should handle internally? |
Adding if (event === 'change' && val1.atime && val1.mtime && val1.atime > val1.mtime) {
return this;
} to FSWatcher.prototype._emit worked for me as a hotfix but I am not sure if it would break other projects. |
I'm running nodemon in a Visual Studio Code task and this behavior is really annoying. VS Code will sporadically cause the access time of multiple files to be updated whenever its git autorefresh feature runs in the background. So I really appreciate your PR, @markablov |
Looks like this is in 2.1.0, see https://www.npmjs.com/package/chokidar/v/2.1.0 |
Given the following in Windows:
When a file is opened but not modified, Chokidar will trigger a change as
LastAccessTime
is modified. All other attributes remain unchanged. See remy/nodemon#1208Versions (please complete the following information):
To Reproduce
Just open a file (changing
LastAccessTime
on a watched file. LMK if you want a demo app.Expected behavior
No changes. Access Time is not considered a change. It is reading, not writing.
The text was updated successfully, but these errors were encountered: