• R/O
  • HTTP
  • SSH
  • HTTPS

Commit

Tags
No Tags

Frequently used words (click to add to your profile)

javac++androidlinuxc#windowsobjective-ccocoa誰得qtpythonphprubygameguibathyscaphec計画中(planning stage)翻訳omegatframeworktwitterdomtestvb.netdirectxゲームエンジンbtronarduinopreviewer

system/corennnnn


Commit MetaInfo

Revisão109d7d23c57dd740af188109ee84ef5fae14617a (tree)
Hora2016-07-14 08:55:34
AutorMark Salyzyn <salyzyn@goog...>
CommiterMark Salyzyn

Mensagem de Log

init: Add support for ${x.y:-default} expansion

commit 00ede7d2626f9343d330dc6f5286bba3e99e41d0 (init: do
expand_props before calling the builtins) broke logpersist

Bug: 28120456
Bug: 22654233
Bug: 28788401
Change-Id: Ib4d8231665b26ac083b02243177493fab41c8978

Mudança Sumário

Diff

--- a/init/util.cpp
+++ b/init/util.cpp
@@ -504,6 +504,7 @@ bool expand_props(const std::string& src, std::string* dst) {
504504 * - will accept $$ as a literal $.
505505 * - no nested property expansion, i.e. ${foo.${bar}} is not supported,
506506 * bad things will happen
507+ * - ${x.y:-default} will return default value if property empty.
507508 */
508509 while (*src_ptr) {
509510 const char* c;
@@ -526,6 +527,7 @@ bool expand_props(const std::string& src, std::string* dst) {
526527 }
527528
528529 std::string prop_name;
530+ std::string def_val;
529531 if (*c == '{') {
530532 c++;
531533 const char* end = strchr(c, '}');
@@ -536,6 +538,11 @@ bool expand_props(const std::string& src, std::string* dst) {
536538 }
537539 prop_name = std::string(c, end);
538540 c = end + 1;
541+ size_t def = prop_name.find(":-");
542+ if (def < prop_name.size()) {
543+ def_val = prop_name.substr(def + 2);
544+ prop_name = prop_name.substr(0, def);
545+ }
539546 } else {
540547 prop_name = c;
541548 ERROR("using deprecated syntax for specifying property '%s', use ${name} instead\n",
@@ -550,9 +557,12 @@ bool expand_props(const std::string& src, std::string* dst) {
550557
551558 std::string prop_val = property_get(prop_name.c_str());
552559 if (prop_val.empty()) {
553- ERROR("property '%s' doesn't exist while expanding '%s'\n",
554- prop_name.c_str(), src.c_str());
555- return false;
560+ if (def_val.empty()) {
561+ ERROR("property '%s' doesn't exist while expanding '%s'\n",
562+ prop_name.c_str(), src.c_str());
563+ return false;
564+ }
565+ prop_val = def_val;
556566 }
557567
558568 dst->append(prop_val);