0

Some of my users requested me a feature to implement live-reload of data files in my app - e.g. they'll edit a file, say foo.txt in some editor, and my app which also uses the content of foo.txt reloads it when it detects the change, by checking mtime regularly (I don't know of other options which support the editors that work by deleting and recreating a file from scratch instead of just modifying it).

I do not understand how one can implement this properly yet every other app seems to have this feature?

As the "editing" app which writes into foo.txt may do multiple calls to write() to write into the modified file - what makes me sure that the version I am reading from my app is going to be the "correct" one and not an intermediary version with half the write(), which could wreak havok?

I saw that there are ways to atomically write, but here I do not control the way the "write" is done. Is there any sane way out of this, which would work on every platform ? (My app ships on Windows, Mac, Linux and WebAssembly though it is likely less relevant there)

Jean-Michaël Celerier
  • 7,412
  • 3
  • 54
  • 75

0 Answers0