Fsync data after writing prefs

update_engine is relying on prefs stored on filesystem to resume OTA
progress. Partners report loss of update progress after forced reboot.
This might be I/O cache issue.

Test: th
Bug: 259174530
Change-Id: I7b4b8281cfe2cc45c51e4d6d60e09edb12f3ed86
diff --git a/common/prefs.cc b/common/prefs.cc
index f33a8a9..41a7b24 100644
--- a/common/prefs.cc
+++ b/common/prefs.cc
@@ -25,6 +25,7 @@
 #include <base/strings/string_split.h>
 #include <base/strings/string_util.h>
 
+#include "brillo/file_utils.h"
 #include "update_engine/common/utils.h"
 
 using std::string;
@@ -202,8 +203,8 @@
     // to parent directories where we might not have permission to write to.
     TEST_AND_RETURN_FALSE(base::CreateDirectory(filename.DirName()));
   }
-  TEST_AND_RETURN_FALSE(base::WriteFile(filename, value.data(), value.size()) ==
-                        static_cast<int>(value.size()));
+  TEST_AND_RETURN_FALSE(
+      utils::WriteStringToFileAtomic(filename.value(), value));
   return true;
 }