Merge "Don't overwrite persistent property files" into main am: 68fbe13281
Original change: https://android-review.googlesource.com/c/platform/system/core/+/2796061 Change-Id: Id7e82d8d586ea9df230c12dea2a3f58addafdc00 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
commit
c5dec993c8
3 changed files with 22 additions and 30 deletions
|
|
@ -115,24 +115,6 @@ void RemoveLegacyPersistentPropertyFiles() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
PersistentProperties LoadPersistentPropertiesFromMemory() {
|
|
||||||
PersistentProperties persistent_properties;
|
|
||||||
__system_property_foreach(
|
|
||||||
[](const prop_info* pi, void* cookie) {
|
|
||||||
__system_property_read_callback(
|
|
||||||
pi,
|
|
||||||
[](void* cookie, const char* name, const char* value, unsigned serial) {
|
|
||||||
if (StartsWith(name, "persist.")) {
|
|
||||||
auto properties = reinterpret_cast<PersistentProperties*>(cookie);
|
|
||||||
AddPersistentProperty(name, value, properties);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
cookie);
|
|
||||||
},
|
|
||||||
&persistent_properties);
|
|
||||||
return persistent_properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
Result<std::string> ReadPersistentPropertyFile() {
|
Result<std::string> ReadPersistentPropertyFile() {
|
||||||
const std::string temp_filename = persistent_property_filename + ".tmp";
|
const std::string temp_filename = persistent_property_filename + ".tmp";
|
||||||
if (access(temp_filename.c_str(), F_OK) == 0) {
|
if (access(temp_filename.c_str(), F_OK) == 0) {
|
||||||
|
|
@ -221,6 +203,24 @@ Result<void> WritePersistentPropertyFile(const PersistentProperties& persistent_
|
||||||
return {};
|
return {};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
PersistentProperties LoadPersistentPropertiesFromMemory() {
|
||||||
|
PersistentProperties persistent_properties;
|
||||||
|
__system_property_foreach(
|
||||||
|
[](const prop_info* pi, void* cookie) {
|
||||||
|
__system_property_read_callback(
|
||||||
|
pi,
|
||||||
|
[](void* cookie, const char* name, const char* value, unsigned serial) {
|
||||||
|
if (StartsWith(name, "persist.")) {
|
||||||
|
auto properties = reinterpret_cast<PersistentProperties*>(cookie);
|
||||||
|
AddPersistentProperty(name, value, properties);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
cookie);
|
||||||
|
},
|
||||||
|
&persistent_properties);
|
||||||
|
return persistent_properties;
|
||||||
|
}
|
||||||
|
|
||||||
// Persistent properties are not written often, so we rather not keep any data in memory and read
|
// Persistent properties are not written often, so we rather not keep any data in memory and read
|
||||||
// then rewrite the persistent property file for each update.
|
// then rewrite the persistent property file for each update.
|
||||||
void WritePersistentProperty(const std::string& name, const std::string& value) {
|
void WritePersistentProperty(const std::string& name, const std::string& value) {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,7 @@ void AddPersistentProperty(const std::string& name, const std::string& value,
|
||||||
PersistentProperties* persistent_properties);
|
PersistentProperties* persistent_properties);
|
||||||
PersistentProperties LoadPersistentProperties();
|
PersistentProperties LoadPersistentProperties();
|
||||||
void WritePersistentProperty(const std::string& name, const std::string& value);
|
void WritePersistentProperty(const std::string& name, const std::string& value);
|
||||||
|
PersistentProperties LoadPersistentPropertiesFromMemory();
|
||||||
|
|
||||||
// Exposed only for testing
|
// Exposed only for testing
|
||||||
Result<PersistentProperties> LoadPersistentPropertyFile();
|
Result<PersistentProperties> LoadPersistentPropertyFile();
|
||||||
|
|
|
||||||
|
|
@ -1400,8 +1400,6 @@ static void HandleInitSocket() {
|
||||||
// Apply staged and persistent properties
|
// Apply staged and persistent properties
|
||||||
bool has_staged_prop = false;
|
bool has_staged_prop = false;
|
||||||
auto const staged_prefix = std::string_view("next_boot.");
|
auto const staged_prefix = std::string_view("next_boot.");
|
||||||
auto const staged_persist_prefix = std::string_view("next_boot.persist.");
|
|
||||||
auto persist_props_map = std::unordered_map<std::string, std::string>();
|
|
||||||
|
|
||||||
auto persistent_properties = LoadPersistentProperties();
|
auto persistent_properties = LoadPersistentProperties();
|
||||||
for (const auto& property_record : persistent_properties.properties()) {
|
for (const auto& property_record : persistent_properties.properties()) {
|
||||||
|
|
@ -1412,23 +1410,16 @@ static void HandleInitSocket() {
|
||||||
has_staged_prop = true;
|
has_staged_prop = true;
|
||||||
auto actual_prop_name = prop_name.substr(staged_prefix.size());
|
auto actual_prop_name = prop_name.substr(staged_prefix.size());
|
||||||
InitPropertySet(actual_prop_name, prop_value);
|
InitPropertySet(actual_prop_name, prop_value);
|
||||||
if (StartsWith(prop_name, staged_persist_prefix)) {
|
} else {
|
||||||
persist_props_map[actual_prop_name] = prop_value;
|
|
||||||
}
|
|
||||||
} else if (!persist_props_map.count(prop_name)) {
|
|
||||||
InitPropertySet(prop_name, prop_value);
|
InitPropertySet(prop_name, prop_value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update persist prop file if there are staged props
|
// Update persist prop file if there are staged props
|
||||||
if (has_staged_prop) {
|
if (has_staged_prop) {
|
||||||
PersistentProperties updated_persist_props;
|
PersistentProperties props = LoadPersistentPropertiesFromMemory();
|
||||||
for (auto const& [prop_name, prop_value] : persist_props_map) {
|
|
||||||
AddPersistentProperty(prop_name, prop_value, &updated_persist_props);
|
|
||||||
}
|
|
||||||
|
|
||||||
// write current updated persist prop file
|
// write current updated persist prop file
|
||||||
auto result = WritePersistentPropertyFile(updated_persist_props);
|
auto result = WritePersistentPropertyFile(props);
|
||||||
if (!result.ok()) {
|
if (!result.ok()) {
|
||||||
LOG(ERROR) << "Could not store persistent property: " << result.error();
|
LOG(ERROR) << "Could not store persistent property: " << result.error();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue