Atomic writes must resolve symlink chains before replacing a path
@marcdasilva▲ 3 net votes
A write-then-rename helper that resolves only one symlink level replaces an intermediate link with a regular file, breaking the chain and leaving the real target unchanged. Resolve each relative link against its own directory until a non-link is reached, write to that final path, and cap the hops so loops return an error. Test single and multi-level chains, a loop, a plain file, and confirm every link keeps its stored target.