aboutsummaryrefslogtreecommitdiff
path: root/tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp')
-rw-r--r--tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp36
1 files changed, 16 insertions, 20 deletions
diff --git a/tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp b/tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp
index cd57f4fb29..cabc65e40c 100644
--- a/tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp
+++ b/tools/aconfig/aconfig_storage_write_api/aconfig_storage_write_api.cpp
@@ -1,7 +1,6 @@
#include <android-base/file.h>
#include <android-base/logging.h>
-#include <protos/aconfig_storage_metadata.pb.h>
#include <sys/mman.h>
#include <sys/stat.h>
@@ -11,45 +10,42 @@
#include "aconfig_storage/lib.rs.h"
#include "aconfig_storage/aconfig_storage_write_api.hpp"
-using storage_records_pb = android::aconfig_storage_metadata::storage_files;
-using storage_record_pb = android::aconfig_storage_metadata::storage_file_info;
-using namespace android::base;
-
namespace aconfig_storage {
/// Map a storage file
-Result<MutableMappedStorageFile> map_mutable_storage_file(std::string const& file) {
+android::base::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";
+ return android::base::ErrnoError() << "stat failed";
}
if ((file_stat.st_mode & (S_IWUSR | S_IWGRP | S_IWOTH)) == 0) {
- return Error() << "cannot map nonwriteable file";
+ return android::base::Error() << "cannot map nonwriteable file";
}
size_t file_size = file_stat.st_size;
const int fd = open(file.c_str(), O_RDWR | O_NOFOLLOW | O_CLOEXEC);
if (fd == -1) {
- return ErrnoError() << "failed to open " << file;
+ return android::base::ErrnoError() << "failed to open " << file;
};
void* const map_result =
mmap(nullptr, file_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (map_result == MAP_FAILED) {
- return ErrnoError() << "mmap failed";
+ return android::base::ErrnoError() << "mmap failed";
}
- auto mapped_file = MutableMappedStorageFile();
- mapped_file.file_ptr = map_result;
- mapped_file.file_size = file_size;
+ auto mapped_file = new MutableMappedStorageFile();
+ mapped_file->file_ptr = map_result;
+ mapped_file->file_size = file_size;
return mapped_file;
}
/// Set boolean flag value
-Result<void> set_boolean_flag_value(
+android::base::Result<void> set_boolean_flag_value(
const MutableMappedStorageFile& file,
uint32_t offset,
bool value) {
@@ -57,13 +53,13 @@ Result<void> set_boolean_flag_value(
static_cast<uint8_t*>(file.file_ptr), file.file_size);
auto update_cxx = update_boolean_flag_value_cxx(content, offset, value);
if (!update_cxx.update_success) {
- return Error() << std::string(update_cxx.error_message.c_str());
+ return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
/// Set if flag has server override
-Result<void> set_flag_has_server_override(
+android::base::Result<void> set_flag_has_server_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
@@ -73,13 +69,13 @@ Result<void> set_flag_has_server_override(
auto update_cxx = update_flag_has_server_override_cxx(
content, static_cast<uint16_t>(value_type), offset, value);
if (!update_cxx.update_success) {
- return Error() << std::string(update_cxx.error_message.c_str());
+ return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
/// Set if flag has local override
-Result<void> set_flag_has_local_override(
+android::base::Result<void> set_flag_has_local_override(
const MutableMappedStorageFile& file,
FlagValueType value_type,
uint32_t offset,
@@ -89,12 +85,12 @@ Result<void> set_flag_has_local_override(
auto update_cxx = update_flag_has_local_override_cxx(
content, static_cast<uint16_t>(value_type), offset, value);
if (!update_cxx.update_success) {
- return Error() << std::string(update_cxx.error_message.c_str());
+ return android::base::Error() << update_cxx.error_message.c_str();
}
return {};
}
-Result<void> create_flag_info(
+android::base::Result<void> create_flag_info(
std::string const& package_map,
std::string const& flag_map,
std::string const& flag_info_out) {