# HG changeset patch # User Pierre-Yves David <pierre-yves.david@octobus.net> # Date 1644397764 -3600 # Wed Feb 09 10:09:24 2022 +0100 # Node ID 85d36c2cb7772cdee2ce4543d5fd57c4bf4a9d1a # Parent d00bf0f38e5526b6af264db436226697dd008282 write the temporary file next to the one we are about to overwrite diff --git a/python-libs/poulpe_helper.py b/python-libs/poulpe_helper.py --- a/python-libs/poulpe_helper.py +++ b/python-libs/poulpe_helper.py @@ -39,9 +39,12 @@ def write_data(path, data): """write description data at <path>""" - with tempfile.NamedTemporaryFile(mode='w', delete=False) as f: + directory = os.path.dirname(path) + basename = os.path.basename(path) + tmp_path = os.path.join(directory, f".{basename}.tmp") + with open(tmp_path, "w") as f: toml.dump(data, f) - os.replace(f.name, path) + os.replace(tmp_path, path) def show(data, indent=''):