Expand description
atomic_write submodule — the shared temp-file-safe shard writer
used by both rkyv caches.
Crash-safe atomic file replacement for the rkyv shard caches.
zshrs-original — no C counterpart. zsh has no persistent bytecode
store, so nothing here mirrors a Src/ function.
Both shard caches replace their file the same way: serialize into a
sibling temp file, fsync, rename over the target. The temp name
embeds the writing pid (<file>.tmp.<pid>.<nanos>), which is what
lets a later writer decide whether an abandoned temp is safe to
delete.
Abandonment was not hypothetical. One ~/.zshrs accumulated 18
orphaned autoloads.rkyv.tmp.<pid>.<nanos> files totalling 517 MB.
Two holes produced them, and both are closed here:
- an error return between
File::createandrenameleft the temp on disk — [TempFileGuard] now unlinks it on every exit path, including the?returns and a panic; - a process killed inside that window never reached the rename at
all — [
reap_orphan_temps] unlinks temps whose recorded pid no longer exists.
A temp owned by a live pid is never touched: it belongs to a
sibling shell that is still mid-write, and deleting it would corrupt
that write. Same reasoning as the .git/index.lock rule — a lock (or
a temp) you did not create is not yours to remove.
Functions§
- reap_
orphan_ temps - Delete
<file>.tmp.<pid>.<nanos>siblings ofpathwhose<pid>is no longer running. Returns how many were removed. - write_
bytes_ atomic - Replace
pathwithbytesatomically, leaving no temp file behind on any exit path, and reap temps abandoned by processes that are gone.