humanlogio / humanlog

Logs for humans to read.
Apache License 2.0
748 stars 53 forks source link

fix: create temporary files in same dir as end destination #58

Closed aybabtme closed 1 year ago

aybabtme commented 1 year ago

To ensure that config and state files are mutated atomically, updates are done by creating a temporary file, writing the new content, and doing an os.rename call to replace the old file with the temporary file. However, until this commit, the temporary file was create in the OS' default temp dir. In some environment (Codespaces), this directory isn't on the same filesystem as the target file.

The solution is to create the temp file in the target directory. It might end up leaving some artifacts if the process were to die before cleaning it up, but that's better than failing on such a common case as having more multiple filesystems.

Fixes https://github.com/humanlogio/humanlog/issues/57