code: def atomic_copy(src, dst):
    
    with temporary_file(root_dir=os.path.dirname(dst)) as tmp_dst:
      shutil.copyfile(src, tmp_dst.name)
      os.chmod(tmp_dst.name, os.stat(src).st_mode)
      os.rename(tmp_dst.name, dst)
docs: Copy the file src to dst, overwriting dst atomically.