imas.backends.imas_core.mdsplus_model.safe_replace

imas.backends.imas_core.mdsplus_model.safe_replace(src: Path, dst: Path) None

Replace a folder from src to dst, overwriting dst if it is empty.

  • Moves must be atomic. shutil.move() is not atomic. Note that multiple threads may try to write to the cache at once, so atomicity is required to ensure the serving on one thread doesn’t pick up a partially saved image from another thread.

  • Moves must work across filesystems. Often temp directories and the cache directories live on different filesystems. os.replace() can throw errors if run across filesystems.

So we try os.replace(), but if we detect a cross-filesystem copy, we switch to shutil.move() with some wrappers to make it atomic.


Last update: 2026-01-28