Here is the scenario: A user creates a new file X.php let's say using nano. The user writes some content, saves the file (Stage S1) but does not exit the nano. He again make some changes and then exit the nano after saving the file again (Stage S2).
Question: I've a piece of code(a trigger) that I need to inject in every php file in a directory. I'm able to do so. But in the upper scenario, as soon as I detect a new file(using inotifywait) is created (Stage S1), I inject my code into it. However, since nano was never closed,thus ,in the next save (Stage S2) my injected code gets overwritten by the new changes of user. How can I get rid of this issue?
P.S.: The editor can be any text editor and I don't know the editor used by the user to create file.