Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 9f236037 authored by Dennis Shen's avatar Dennis Shen
Browse files

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
parent 36661d4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ rust_protobuf {
    min_sdk_version: "29",
}

cc_library_static {
cc_library {
    name: "libaconfig_storage_protos_cc",
    proto: {
        export_proto_headers: true,
+2 −1
Original line number Diff line number Diff line
@@ -27,7 +27,8 @@ message storage_file_info {
  optional string flag_map = 4;
  optional string flag_val = 5;
  optional string flag_info = 6;
  optional int64 timestamp = 7;
  optional string local_overrides = 7;
  optional int64 timestamp = 8;
}

message storage_files {
+24 −23
Original line number Diff line number Diff line
@@ -66,8 +66,31 @@ static Result<std::string> find_storage_file(
  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
static Result<MutableMappedStorageFile> map_storage_file(std::string const& file) {
Result<MutableMappedStorageFile> map_mutable_storage_file(std::string const& file) {
  struct stat file_stat;
  if (stat(file.c_str(), &file_stat) < 0) {
    return ErrnoError() << "stat failed";
@@ -97,28 +120,6 @@ static Result<MutableMappedStorageFile> map_storage_file(std::string const& 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
Result<MutableMappedStorageFile> get_mutable_mapped_file(
    std::string const& container,
+4 −0
Original line number Diff line number Diff line
@@ -26,6 +26,10 @@ Result<MutableMappedStorageFile> get_mutable_mapped_file_impl(

} // namespace private_internal_api

/// Map a storage file
Result<MutableMappedStorageFile> map_mutable_storage_file(
    std::string const& file);

/// Get mapped writeable storage file
Result<MutableMappedStorageFile> get_mutable_mapped_file(
    std::string const& container,