aconfig: add support for local override

1, add a new field in storage metadata proto, for each container, there
is a local override file.

2, update write api to expose the api to map a writable file given the
specific path. the cannonical api will require a storage metadata proto,
and then find the right file path and map it.

3, minor update to make the proto lib cc_library instead of
cc_library_static

Bug: b/312444587
Test: atest -c
Change-Id: Iaf0aff44c1ca3ad4bffc5e06bb99bb276b9069c5
This commit is contained in:
Dennis Shen 2024-04-17 12:25:11 +00:00
parent 36661d4cd0
commit 9f236037a2
4 changed files with 31 additions and 25 deletions

View file

@ -56,7 +56,7 @@ rust_protobuf {
min_sdk_version: "29", min_sdk_version: "29",
} }
cc_library_static { cc_library {
name: "libaconfig_storage_protos_cc", name: "libaconfig_storage_protos_cc",
proto: { proto: {
export_proto_headers: true, export_proto_headers: true,

View file

@ -27,7 +27,8 @@ message storage_file_info {
optional string flag_map = 4; optional string flag_map = 4;
optional string flag_val = 5; optional string flag_val = 5;
optional string flag_info = 6; optional string flag_info = 6;
optional int64 timestamp = 7; optional string local_overrides = 7;
optional int64 timestamp = 8;
} }
message storage_files { message storage_files {

View file

@ -66,8 +66,31 @@ static Result<std::string> find_storage_file(
return Error() << "Unable to find storage files for container " << container; return Error() << "Unable to find storage files for container " << container;
} }
namespace private_internal_api {
/// Get mutable mapped file implementation.
Result<MutableMappedStorageFile> get_mutable_mapped_file_impl(
std::string const& pb_file,
std::string const& container,
StorageFileType file_type) {
if (file_type != StorageFileType::flag_val &&
file_type != StorageFileType::flag_info) {
return Error() << "Cannot create mutable mapped file for this file type";
}
auto file_result = find_storage_file(pb_file, container, file_type);
if (!file_result.ok()) {
return Error() << file_result.error();
}
return map_mutable_storage_file(*file_result);
}
} // namespace private internal api
/// Map a storage file /// Map a storage file
static Result<MutableMappedStorageFile> map_storage_file(std::string const& file) { Result<MutableMappedStorageFile> map_mutable_storage_file(std::string const& file) {
struct stat file_stat; struct stat file_stat;
if (stat(file.c_str(), &file_stat) < 0) { if (stat(file.c_str(), &file_stat) < 0) {
return ErrnoError() << "stat failed"; return ErrnoError() << "stat failed";
@ -97,28 +120,6 @@ static Result<MutableMappedStorageFile> map_storage_file(std::string const& file
return mapped_file; return mapped_file;
} }
namespace private_internal_api {
/// Get mutable mapped file implementation.
Result<MutableMappedStorageFile> get_mutable_mapped_file_impl(
std::string const& pb_file,
std::string const& container,
StorageFileType file_type) {
if (file_type != StorageFileType::flag_val &&
file_type != StorageFileType::flag_info) {
return Error() << "Cannot create mutable mapped file for this file type";
}
auto file_result = find_storage_file(pb_file, container, file_type);
if (!file_result.ok()) {
return Error() << file_result.error();
}
return map_storage_file(*file_result);
}
} // namespace private internal api
/// Get mutable mapped file /// Get mutable mapped file
Result<MutableMappedStorageFile> get_mutable_mapped_file( Result<MutableMappedStorageFile> get_mutable_mapped_file(
std::string const& container, std::string const& container,

View file

@ -26,6 +26,10 @@ Result<MutableMappedStorageFile> get_mutable_mapped_file_impl(
} // namespace private_internal_api } // namespace private_internal_api
/// Map a storage file
Result<MutableMappedStorageFile> map_mutable_storage_file(
std::string const& file);
/// Get mapped writeable storage file /// Get mapped writeable storage file
Result<MutableMappedStorageFile> get_mutable_mapped_file( Result<MutableMappedStorageFile> get_mutable_mapped_file(
std::string const& container, std::string const& container,