uniqueTempFile

fun uniqueTempFile(file: Path): Path

A staging path unique to a single codec, of the form <file>.<random>.temp.

Stores pointing at the same file each get their own staging file. Sharing one lets concurrent writes interleave into a single buffer before either is moved into place, and whichever moves last publishes the mixture, which is how a store ends up corrupt on disk (see issue #85). With a staging file each, the move stays atomic and the worst case is last write wins.

Note this is one staging file per codec, not per write, so a process killed mid-write leaves at most one behind per store. The next write is unaffected either way.

The suffix comes from Uuid.random rather than kotlin.random.Random on purpose. Random.Default is a PRNG seeded from the clock on some targets, so two processes cold starting in the same tick can draw the same sequence and land on the same staging path, which is the one case this is meant to prevent. Uuid.random draws from the platform's secure source and has no shared seed.

Return

a staging path that no other codec will pick

Parameters

file

path to the file being staged for