chokidar icon indicating copy to clipboard operation
chokidar copied to clipboard

Change event is fired when file is opened

Open dominicpaul1911 opened this issue 5 years ago • 12 comments

Describe the bug Change event is fired when a file is opened.

When watching a folder, opening a file triggers a change event, even though the file has not been modified. Tested it with images, movies, text files etc.

Versions (please complete the following information):

  • Chokidar version [e.g. 3.2.1 or commit hash] "chokidar": "^3.3.1"
  • Node version [e.g. 12.11.0, ensure you are using the latest node.js] v12.11.1
  • OS version: [e.g. Ubuntu 19.04 or MacOS 10.15 or Windows 10] MacOS 10.15.3
const chokidar = require('chokidar')

let TMP_WATCHER = chokidar.watch('/Users/dominic/code/test', {
    awaitWriteFinish: {
        stabilityThreshold: 2000,
        pollInterval: 100
    },
    alwaysStat: true,
})

TMP_WATCHER.on('add', (file, stats) => {
    console.log('add', file)
})

TMP_WATCHER.on('change', (file, stats) => {
    console.log('change', file)
})

Expected behavior Should not fire change event unless there is a change in the file

dominicpaul1911 avatar Mar 05 '20 15:03 dominicpaul1911

Opened with what?

paulmillr avatar Mar 05 '20 15:03 paulmillr

Any respective application. For example images with Preview app, movie with Quick time, txt with Sublime etc.

dominicpaul1911 avatar Mar 05 '20 16:03 dominicpaul1911

Could you test this with 3.0 or 3.1?

paulmillr avatar Mar 06 '20 07:03 paulmillr

So the same behavior in previous versions as well. Digging in further looks like fs.watch has the same issue. Whenever a file opened, it fires a change event.

dominicpaul1911 avatar Mar 07 '20 03:03 dominicpaul1911

Interesting. Our low-level fsevents pkg reports unknown event when a file is opened, but no one reported this.

paulmillr avatar Mar 07 '20 06:03 paulmillr

Is it possible that it's reporting an change of atime?

pipobscure avatar Nov 03 '20 13:11 pipobscure

Yeah it is a change of atime but i don't think this is supposed to happen as described in this issue. Somehow it got closed for some reason https://github.com/paulmillr/chokidar/issues/750 but this is still an issue.

Listor avatar Nov 30 '20 11:11 Listor

Just ran into this issue today with image files (.png to be specific). It occurs every time I open the file in Preview.

aspctu avatar Apr 01 '22 00:04 aspctu

Yes, it still happens for every kind of opening (even when folders are opened in Finder).

taratatach avatar Apr 13 '22 16:04 taratatach

Just ran into this issue today with image files (.png to be specific). It occurs every time I open the file in Preview.

This is still the case today with version 3.5.3

AlexandreSi avatar Sep 05 '23 14:09 AlexandreSi

Still an issue in October 2023, anything we can do to help?

martinbavio avatar Oct 17 '23 20:10 martinbavio

@marbiano unfortunately only a pull req

paulmillr avatar Oct 18 '23 11:10 paulmillr