Function rustc_metadata::fs::non_durable_rename
source · Expand description
This function attempts to bypass the auto_da_alloc heuristic implemented by some filesystems such as btrfs and ext4. When renaming over a file that already exists then they will “helpfully” write back the source file before committing the rename in case a developer forgot some of the fsyncs in the open/write/fsync(file)/rename/fsync(dir) dance for atomic file updates.
To avoid triggering this heuristic we delete the destination first, if it exists. The cost of an extra syscall is much lower than getting descheduled for the sync IO.