summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDennis Shen <dzshen@google.com>2024-04-05 16:51:42 +0000
committerDennis Shen <dzshen@google.com>2024-04-09 13:26:50 +0000
commit260c7f3a5f394cfaabe6e6a2ab17e132fb8ff846 (patch)
tree938a6d14f0cffdbfd4f875d1eff8b3ec1f84be9e
parenta06fb0175107926acf98e14a01f3ad9a78c918d5 (diff)
downloadserver_configurable_flags-260c7f3a5f394cfaabe6e6a2ab17e132fb8ff846.tar.gz
aconfigd: create flag info file when a new container is added
Bug: b/312444587 Test: m and launch avd Change-Id: I2ff3c8b24cfd2bb57b14734dde78b58e5d57ee7e
-rw-r--r--aconfigd/aconfigd.cpp24
-rw-r--r--aconfigd/tests/flag.mapbin321 -> 321 bytes
-rw-r--r--aconfigd/tests/flag.valbin35 -> 35 bytes
3 files changed, 23 insertions, 1 deletions
diff --git a/aconfigd/aconfigd.cpp b/aconfigd/aconfigd.cpp
index 7586cbd..6b51231 100644
--- a/aconfigd/aconfigd.cpp
+++ b/aconfigd/aconfigd.cpp
@@ -52,6 +52,7 @@ struct StorageRecord {
std::string package_map;
std::string flag_map;
std::string flag_val;
+ std::string flag_info;
int timestamp;
StorageRecord() = default;
@@ -62,6 +63,7 @@ struct StorageRecord {
, package_map(entry.package_map())
, flag_map(entry.flag_map())
, flag_val(entry.flag_val())
+ , flag_info(entry.flag_info())
, timestamp(entry.timestamp())
{}
};
@@ -122,6 +124,7 @@ Result<void> WritePersistentStorageRecordsToFile() {
record_pb->set_package_map(entry.package_map);
record_pb->set_flag_map(entry.flag_map);
record_pb->set_flag_val(entry.flag_val);
+ record_pb->set_flag_info(entry.flag_info);
record_pb->set_timestamp(entry.timestamp);
}
@@ -138,13 +141,15 @@ Result<void> CreateBootSnapshotForContainer(const std::string& container) {
// create boot copy
auto src_value_file = std::string("/metadata/aconfig/flags/") + container + ".val";
auto dst_value_file = std::string("/metadata/aconfig/boot/") + container + ".val";
+ auto src_info_file = std::string("/metadata/aconfig/flags/") + container + ".info";
+ auto dst_info_file = std::string("/metadata/aconfig/boot/") + container + ".info";
// If the boot copy already exists, do nothing. Never update the boot copy, the boot
// copy should be boot stable. So in the following scenario: a container storage
// file boot copy is created, then an updated container is mounted along side existing
// container. In this case, we should update the persistent storage file copy. But
// never touch the current boot copy.
- if (FileExists(dst_value_file)) {
+ if (FileExists(dst_value_file) || FileExists(dst_info_file)) {
return {};
}
@@ -154,6 +159,12 @@ Result<void> CreateBootSnapshotForContainer(const std::string& container) {
<< copy_result.error();
}
+ copy_result = CopyFile(src_info_file, dst_info_file, 0444);
+ if (!copy_result.ok()) {
+ return Error() << "CopyFile failed for " << src_info_file << " :"
+ << copy_result.error();
+ }
+
// update available storage records pb
auto const& entry = persist_storage_records[container];
auto records_pb = ReadStorageRecordsPb(kAvailableStorageRecordsFileName);
@@ -168,6 +179,7 @@ Result<void> CreateBootSnapshotForContainer(const std::string& container) {
record_pb->set_package_map(entry.package_map);
record_pb->set_flag_map(entry.flag_map);
record_pb->set_flag_val(dst_value_file);
+ record_pb->set_flag_info(dst_info_file);
record_pb->set_timestamp(entry.timestamp);
auto write_result = WriteStorageRecordsPbToFile(
@@ -208,6 +220,15 @@ Result<bool> HandleContainerUpdate(const std::string& container,
return Error() << "Failed to get storage version: " << version_result.error();
}
+ // create flag info file
+ auto flag_info_file = std::string("/metadata/aconfig/flags/") + container + ".info";
+ auto create_result = aconfig_storage::create_flag_info(
+ package_file, flag_file, flag_info_file);
+ if (!create_result.ok()) {
+ return Error() << "Failed to create flag info file for container " << container
+ << ": " << create_result.error();
+ }
+
// add to in memory storage file records
auto& record = persist_storage_records[container];
record.version = *version_result;
@@ -215,6 +236,7 @@ Result<bool> HandleContainerUpdate(const std::string& container,
record.package_map = package_file;
record.flag_map = flag_file;
record.flag_val = target_value_file;
+ record.flag_info = flag_info_file;
record.timestamp = *timestamp;
// write to persistent storage records file
diff --git a/aconfigd/tests/flag.map b/aconfigd/tests/flag.map
index c1dab4a..d26e00f 100644
--- a/aconfigd/tests/flag.map
+++ b/aconfigd/tests/flag.map
Binary files differ
diff --git a/aconfigd/tests/flag.val b/aconfigd/tests/flag.val
index 3c82f31..ed203d4 100644
--- a/aconfigd/tests/flag.val
+++ b/aconfigd/tests/flag.val
Binary files differ