Skip to main content

write_file_atomic

Function write_file_atomic 

Source
pub fn write_file_atomic(path: &Path, content: &str) -> Result<()>
Expand description

原子写入:内容写入 path 同目录的临时文件后 rename 覆盖

  • 父目录不存在时自动创建(与各调用点现有一致)
  • 临时文件名 = {文件名}.tmp(与历史 write_card_atomic 的约定一致, 崩溃残留的 .tmp 会被下次写入覆盖,无需清理逻辑)
  • rename 覆盖目标为原子操作(POSIX 语义,见模块注释)