0

I use VSC as an editor on Windows 10 Pro and want to sync to a remote server on file change.

I installed WSL with a debian guest system

If I run this script

while inotifywait -r -e modify,create,delete /path/to/folder; do
  rsync -rltzv --progress --chmod=0600 --exclude=.git/ --exclude=.vscode /path/to/folder user@example.com:~/remote/folder;
done;

The rsync is started not only, when I save a file in VSC, but also, when I open it. While this is not critical, it is annoying and a wast of bandwidth.

Can I do anything against it?

Edit

I don't know, what coused this, but the problem doesn't seem to happen any more on my machine with my setting. But I didn't change anything

  • This could be caused by the creation of a lock file or a backup copy or some local logging, so not really an "open" event (for which there is a specific filter in inotifywait). With the proper rsync option there shouldn't be much bandwidth wasted anyway. Since you use Git a better option would be to use a Git hook to update the server when you commit. – xenoid Aug 13 at 12:39
  • @xenoid There is no lock file or anything like that. inotifywait exactly tells me which event of what file is registered and it the MODIFY event of the just opened file. – yunzen Aug 13 at 12:46
  • @xenoid What would be these proper rsync options? – yunzen Aug 13 at 12:47
  • @xenoid I cannot use git to do this, as I need the sync on file change, not on commit – yunzen Aug 13 at 12:47
0

You are monitoring too many events[*]. The events that matter are:

  • CLOSE_WRITE, because putting data in files requires to close them. You can also consider that the file is in a consistent state at that point.
  • DELETE, for files that are removed
  • MOVED_TO, MOVED_FROM for files that are added to the tree, moved out of it, or just renamed.

[*] For instance, experimentally, MODIFY happens many times (probably for each write operation on the file) and copying the file at that point could copy a file in an inconsistent state. Likewise, OPEN occurs even if you don't make any changes later.

  • From inotifywait man page: close_write: A watched file or a file within a watched directory was closed, after being opened in writeable mode. This does not necessarily imply the file was written to. – yunzen Aug 13 at 14:30
  • This will not work (at least not in WSL). The saving of a file doesn't dispatch any of those events you listed. Only modify does – yunzen Aug 13 at 14:36
  • Strange, works with my editor (kate) and other Linux utilities (touch, piping...). The problem with MODIFY is that you don't know if this is the final edit. Did you try inotifywait -m and can you add the complete sequence of received events to your question (not using -m may makes you miss events while inotifywait is restarted)? – xenoid Aug 13 at 14:48
  • Strange is, the problem doesn't occur any more on my machine – yunzen Aug 13 at 14:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.