How does syncthing create new files within a shared folder?

Hello everyone,

I’m running syncthing since a while now syncing stuff between multiple devices mainly through a remote server (practically, not technically). Now I’ve written a small ruby program using which should listen for freshly synced files within a shared folder and process a file once created within a watched folder. Now the problem is, that syncthing behaves unexpectedly: My ruby code is not able to catch a file freshly created by syncthing within my added handler but rather within modified. The details of the ruby library shall not matter here (I hope), after some reading and rewriting the program I understood that Syncthing creates a temporary file during the syncronisation which after transfer completion becomes moved filename-wise to the final filename. That would sort of explain my discoveries with my small piece of software.

Before I rewrite pieces of the code I wanted to know whether this understanding is correct?

best and thx, Andi

Syncthing creates a temp file, writes the content to the temp file, and then moves the file to it’s final location, to make the “write” operation “atomic”.

Thanks for your reply. What do you mean by “atomic”?

Well renames are atomic, as in the file either moves are not, so we use that to make content atomic, so either the file is there with all of its new content or it’s not. We never have files with partial content in it’s final location, because if syncthing got shutdown half way through a write, we’d be left with half of a file which we’d detect as our won local change and propagate back to others, corrupting it everywhere.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.