| // Copyright (c) 2022 The Chromium Authors. All rights reserved. |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| #include "util/atomic_write.h" |
| #include "base/files/file_util.h" |
| int WriteFileAtomically(const base::FilePath& filename, |
| base::FilePath dir = filename.DirName(); |
| base::FilePath temp_file_path; |
| base::CreateAndOpenTemporaryFileInDir(dir, &temp_file_path); |
| if (!temp_file.IsValid()) { |
| if (temp_file.WriteAtCurrentPos(data, size) != size) { |
| if (!base::ReplaceFile(temp_file_path, filename, NULL)) { |