I'm trying to use Java File Watcher to listen for changes in a file. When I edit the file with vim the File Watcher detect the changes. But when I replace word in file using sed, the file watcher doesn't recognize the changes. I can see the modify date is right.
watchService = FileSystems.getDefault().newWatchService();
Path parent = file.getParent();
parent.register(watchService,
StandartWatchEventKinds.ENTRY_MODIFY
);
The sed command looks something like that:
sed -i 's/a/b/g' file.csv
The sed command itself works, the file actually get changed and the modified date is changed also but for some reason the fire watcher doesn't
Java version - openjdk version 1.8.0_222
Update
So I've got it working, At the beginning I tried an ansible script and I have used the module 'replace' and it didn't word, therefor I tried to change the file locally with sed as mentioned above with no success.
Now I've got it working by making a different ansible script,
In the new script I have copied the wanted file to a tmp file using cp
command, then using the 'replace' module on the tmp file and finally copying the tmp file back to the wanted one.
I'm not really sure why that solved it.
I've also found out that using the 'copy' module of ansible for the process I've described above doesn't help, an just buy using shell cp
it fires the filewatcher.
Even if I've solved it I would like to hear if you know why does the file watcher doesn't fire when changes are made using sed