Node: fs.watch(): reports delete of file as change instead of rename

Created on 25 May 2019  路  7Comments  路  Source: nodejs/node

  • Version: 12.0.0
  • Platform: Darwin Benjamins-MacBook-Pro.local 18.6.0 Darwin Kernel Version 18.6.0: Thu Apr 25 23:16:27 PDT 2019; root:xnu-4903.261.4~2/RELEASE_X86_64 x86_64

Given the following code:

var fs = require("fs");

fs.watch('./test.txt', (event, filename) => {
    console.log(event, filename);
})

Running below in a directory where test.txt exists and gets deleted yields different results for event in 12.x vs 10.x:

  • 12.x: change
  • 10.x: rename

This basically renders node.js 12 incapable of detecting a file delete vs change when watching it.

confirmed-bug fs libuv

Most helpful comment

There's been precisely one change to fsevents.c between v10.15.3 and v12.0.0: libuv/libuv@2d2af382ce84b91d6ee7a185af32fca7f0acd84b

All 7 comments

there was no change in the fs_event binding logic, so perhaps this was an upstream change in libuv? @nodejs/libuv

There's been precisely one change to fsevents.c between v10.15.3 and v12.0.0: libuv/libuv@2d2af382ce84b91d6ee7a185af32fca7f0acd84b

@bnoordhuis for those not familiar with the libuv codebase, is that commit responsible for this behaviour change?

@devsnek I don't know, I haven't had a chance to test. But if it is a libuv issue, it must be that commit.

If someone can try reverting that patch in master or v12.x with git apply -R --directory=deps/uv and checking if that fixes the issue, that would be great.

libuv/libuv@2d2af38 is indeed responsible for the change in behavior. I'm working on a fix.

I've bundled the reported issues in #29460. That's the issue to track now.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

filipesilvaa picture filipesilvaa  路  3Comments

danielstaleiny picture danielstaleiny  路  3Comments

dfahlander picture dfahlander  路  3Comments

stevenvachon picture stevenvachon  路  3Comments

srl295 picture srl295  路  3Comments