Skip to content

Commit 6a22c32

Browse files
committed
Use key-equals-value parsing for reading config= values.
Bug: b/438847412
1 parent 68ff6c3 commit 6a22c32

File tree

2 files changed

+15
-22
lines changed

2 files changed

+15
-22
lines changed

base/cvd/cuttlefish/host/libs/config/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ cf_cc_library(
2626
srcs = ["config_flag.cpp"],
2727
hdrs = ["config_flag.h"],
2828
deps = [
29+
"//cuttlefish/common/libs/key_equals_value",
2930
"//cuttlefish/common/libs/utils:files",
3031
"//cuttlefish/common/libs/utils:flag_parser",
3132
"//cuttlefish/common/libs/utils:json",

base/cvd/cuttlefish/host/libs/config/config_flag.cpp

Lines changed: 14 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616

1717
#include "cuttlefish/host/libs/config/config_flag.h"
1818

19+
#include <map>
1920
#include <optional>
2021
#include <ostream>
2122
#include <set>
@@ -36,6 +37,7 @@
3637
#include <json/value.h>
3738
#include <json/writer.h>
3839

40+
#include "cuttlefish/common/libs/key_equals_value/key_equals_value.h"
3941
#include "cuttlefish/common/libs/utils/files.h"
4042
#include "cuttlefish/common/libs/utils/flag_parser.h"
4143
#include "cuttlefish/common/libs/utils/json.h"
@@ -168,31 +170,21 @@ class ConfigFlagImpl : public ConfigFlag {
168170
if(!ReadFileToString(info_path, &android_info)) {
169171
return {};
170172
}
171-
// grab the config with name "config" in android-info.txt,
172-
// it's the setting that's respected.
173-
// TODO (rammuthiah) Replace this logic with ParseMiscInfo
174-
// from host/commands/assemble_cvd/misc_info.h
175-
// Currently blocked on linking error for misc_info which is part of
176-
// assemble_cvd and this bit of code which is in run_cvd.
177-
auto split_config = Split(android_info, "\n");
178-
if (split_config.empty()) {
173+
Result<std::map<std::string, std::string>> parsed_config =
174+
ParseKeyEqualsValue(android_info);
175+
if (!parsed_config.ok()) {
179176
return {};
180177
}
181-
182-
for (std::string_view local_config_value : split_config) {
183-
if (!android::base::ConsumePrefix(&local_config_value, "config=")) {
184-
continue;
185-
}
186-
187-
if (!config_reader_.HasConfig(std::string{local_config_value})) {
188-
LOG(WARNING) << info_path << " contains invalid config preset: '"
189-
<< local_config_value << "'.";
190-
return {};
191-
}
192-
return std::string{local_config_value};
178+
auto config_it = parsed_config->find("config");
179+
if (config_it == parsed_config->end()) {
180+
return {};
193181
}
194-
195-
return {};
182+
if (!config_reader_.HasConfig(config_it->second)) {
183+
LOG(WARNING) << info_path << " contains invalid config preset: '"
184+
<< config_it->second << "'.";
185+
return {};
186+
}
187+
return config_it->second;
196188
}
197189

198190
ConfigReader& config_reader_;

0 commit comments

Comments
 (0)