summaryrefslogtreecommitdiff
path: root/artd/file_utils.h
diff options
context:
space:
mode:
author Jiakai Zhang <jiakaiz@google.com> 2024-04-19 13:10:58 +0100
committer Jiakai Zhang <jiakaiz@google.com> 2024-04-30 10:43:18 +0000
commit256d751dd830fc6bf28f8b1aa99346e3b951e4c1 (patch)
treebecbb4e551d7913e8fd06ddadd8a29a85e8c97bc /artd/file_utils.h
parentbd45d4629ef5a62baab677ef4e7708a89ff6ec12 (diff)
Refactor NewFile::CommitAllOrAbandon.
This refactoring creates a more generic function to back NewFile::CommitAllOrAbandon, which can be used for moving any files. The generic function will be used for moving Pre-reboot Dexopt staged files. Bug: 311377497 Test: m test-art-host-gtest-art_artd_tests Change-Id: If17392557229d857743011942d0a666e925a0448
Diffstat (limited to 'artd/file_utils.h')
-rw-r--r--artd/file_utils.h20
1 files changed, 19 insertions, 1 deletions
diff --git a/artd/file_utils.h b/artd/file_utils.h
index b5fd170676..a97f52c42a 100644
--- a/artd/file_utils.h
+++ b/artd/file_utils.h
@@ -113,7 +113,6 @@ class NewFile {
std::string temp_path_;
std::string temp_id_;
aidl::com::android::server::art::FsPermission fs_permission_;
- bool committed_ = false;
};
// Opens a file for reading.
@@ -129,6 +128,25 @@ mode_t DirFsPermissionToMode(const aidl::com::android::server::art::FsPermission
android::base::Result<void> Chown(
const std::string& path, const aidl::com::android::server::art::FsPermission& fs_permission);
+// Moves every file in `files_to_move` from a given location to another, replacing the existing file
+// at the destination if it exists, and removes files in `files_to_remove` in addition. Or abandons
+// all files in `files_to_move` and restores old files at best effort if any error occurs.
+//
+// This function does not accept duplicate paths. Passing duplicate paths to this function leads to
+// undefined behavior.
+//
+// Note: This function is NOT thread-safe. It is intended to be used in single-threaded code or in
+// cases where some race condition is acceptable.
+//
+// Usage:
+//
+// Move file at `path_1` to `path_2`, move file at `path_3` to `file_4`, and remove the file at
+// "path_5":
+// MoveAllOrAbandon({{"path_1", "path_2"}, {"path_3", "path_4}}, {"path_5"});
+android::base::Result<void> MoveAllOrAbandon(
+ const std::vector<std::pair<std::string_view, std::string_view>>& files_to_move,
+ const std::vector<std::string_view>& files_to_remove = {});
+
} // namespace artd
} // namespace art