fs.watch - on change returns incorrect file name #19170
Description
In another project, I ran into the following scenario:
The function os.tmpDir returns a path with the 8.3 short name for the user name, example "C:\Users\<FIRST SIX CHARS OF NAME>~1\AppData\Local\Temp".
The Windows api returns the changed file name including the long version of the user name, example,
"C:\Users\<actual 18 char user name>\AppData\Local\Temp".
Pretend we are monitoring, "C:\Users\<8.3 file name>\AppData\Local\Temp\Configuration", expecting the file "config.json" to change. We would then expect the FSWatcher change event to return "config.json" as the name of the changed file. Instead, it returns something like "figuration\config.json", depending on the difference in length between the 8.3 file name and the actual file name.
It seems that node is saving an index so that it can quickly determine the part of the uri that is the file name, but the uri passed to fs.watch is a different length than the uri returned by the Windows api.
Activity
seishun commentedon Mar 7, 2018
It's not clear from your description how one can reproduce this issue. Can you provide a test case?
captainrdubb commentedon Mar 7, 2018
@seishun
bzoz commentedon Mar 8, 2018
Its a libuv issue. The wrong relative filename is created in fs-event.c.
captainrdubb commentedon Mar 8, 2018
@bzoz Maybe we need the long_dirw, instead of passing handle->dirw

bzoz commentedon Mar 8, 2018
I think we should get long directory name here: https://github.com/libuv/libuv/blob/v1.x/src/win/fs-event.c#L200.
win: use long directory name for handle->dirw
bzoz commentedon Mar 19, 2018
@seishun fixed this in libuv
deps: upgrade libuv to 1.20.0
deps: upgrade libuv to 1.20.0
deps: upgrade libuv to 1.20.0