From 07283e09088b8de18d01654042047d142947c6f1 Mon Sep 17 00:00:00 2001 From: Luik Date: Mon, 12 Oct 2026 18:06:15 +0200 Subject: [PATCH] fix: atomically replace canonical markers during migration --- admin/BIOMERO_Migrate_Shallow_Storage.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/admin/BIOMERO_Migrate_Shallow_Storage.py b/admin/BIOMERO_Migrate_Shallow_Storage.py index 9dbfd4e..89cb02d 100644 --- a/admin/BIOMERO_Migrate_Shallow_Storage.py +++ b/admin/BIOMERO_Migrate_Shallow_Storage.py @@ -4,6 +4,7 @@ import json import logging +import os from pathlib import Path import re import shutil @@ -901,7 +902,15 @@ def _json_record(item): def _write_json(path, value): - path.write_text(json.dumps(value, indent=2, sort_keys=True), encoding="utf-8") + temporary = path.with_name(f".{path.name}.{uuid4().hex}.tmp") + try: + with temporary.open("w", encoding="utf-8") as output: + output.write(json.dumps(value, indent=2, sort_keys=True)) + output.flush() + os.fsync(output.fileno()) + os.replace(temporary, path) + finally: + temporary.unlink(missing_ok=True) def _migration_directory_path(value):