Describe how to replace a file atomically while preserving the old file if writing fails.