notify
notify copied to clipboard
How can I get the events from the files that are not closed on windows?
I'm using notify to watch csv files that are generated by another app on windows. During the development stage, all the files tested on wsl, everything were good. However, when I test on windows right now, no events emit by the files,which are read-only and the app holds the writing, unless the app shut down. I'm not familiar with the file system on windows or linux(ubuntu wsl) and not clear why it works on ubuntu wsl but not windows. Thanks for the awesome project.
I can reproduce this on Windows and on MacOS. Here's a reproduction using a python script to write:
from time import sleep
with open("test.txt", "a") as f:
while True:
f.write("foo\n")
f.flush()
print("wrote")
sleep(2)
Using the monitor-raw.rs
sample to read test.txt
, no events are generated until the python script is terminated.
tail -f test.txt
shows the file being written to as expected.
On Windows, if you run Get-Content -Tail 10 -Wait
, then events begin to get generated by notify.
My current guess is that windows doesn't flush the file and waits with change reports until either the file handle is closed, the application is closed or a certain time is passed.
You can also watch this happen in explorer when download/moving giant files: The file size stays at (for example) 0KB while you know that the download progress is happening, and F5/refresh in explorer won't help. But if you right click on the file and go to Properties, then suddenly the actual size is reported (but not updated unless you redo this all the time). From what I know it's kinda the same with windows defender, where closing a file handle blocks until the virus scan finished - so events are happening only then.
Whether we can change/"fix" this behaviour on windows I can't say right now.
This issue is not Windows specific. I was able to reproduce this behavior on MacOS and Windows per my comment. Further, the Get-Content -Tail -Wait
behavior in Windows and tail -f
behavior in MacOS implies that flushing is not the issue at hand.