Improve atomiticy of update checkpointing
Current check point works by writing different prefs to different files
under a pending directory, and rename the pending directory to actual pref
directory afterwards to achieve atomicity. It has two pitfalls:
1. Before the rename() call, existing prefs dir must be rm -rf'ed , this
deletion process isn't atomic. If device rebooted during rm -rf, we
will end up with a partially deleted old pref.
2. fsync() on the parent directory is needed after rename()
This CL addresses both issues. For #1, we rename() the old pref dir to a
tmp dir first, and then rm -rf the tmp dir. Upon device restart, if the
current prefs dir is empty, we can simply rename() the pending directory
to actual pref directory.
Test: th
Bug: 295252766
Change-Id: Ic671a18245986c579b51d7443c3e8c10e206c448
diff --git a/common/utils.h b/common/utils.h
index 0c8c13f..6bb89f1 100644
--- a/common/utils.h
+++ b/common/utils.h
@@ -162,6 +162,7 @@
bool SendFile(int out_fd, int in_fd, size_t count);
bool FsyncDirectory(const char* dirname);
+bool DeleteDirectory(const char* dirname);
bool WriteStringToFileAtomic(const std::string& path, std::string_view content);
// Returns true if the file exists for sure. Returns false if it doesn't exist,