system/corennnnn
Revisão | 109d7d23c57dd740af188109ee84ef5fae14617a (tree) |
---|---|
Hora | 2016-07-14 08:55:34 |
Autor | Mark Salyzyn <salyzyn@goog...> |
Commiter | Mark Salyzyn |
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
@@ -504,6 +504,7 @@ bool expand_props(const std::string& src, std::string* dst) { | ||
504 | 504 | * - will accept $$ as a literal $. |
505 | 505 | * - no nested property expansion, i.e. ${foo.${bar}} is not supported, |
506 | 506 | * bad things will happen |
507 | + * - ${x.y:-default} will return default value if property empty. | |
507 | 508 | */ |
508 | 509 | while (*src_ptr) { |
509 | 510 | const char* c; |
@@ -526,6 +527,7 @@ bool expand_props(const std::string& src, std::string* dst) { | ||
526 | 527 | } |
527 | 528 | |
528 | 529 | std::string prop_name; |
530 | + std::string def_val; | |
529 | 531 | if (*c == '{') { |
530 | 532 | c++; |
531 | 533 | const char* end = strchr(c, '}'); |
@@ -536,6 +538,11 @@ bool expand_props(const std::string& src, std::string* dst) { | ||
536 | 538 | } |
537 | 539 | prop_name = std::string(c, end); |
538 | 540 | 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 | + } | |
539 | 546 | } else { |
540 | 547 | prop_name = c; |
541 | 548 | 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) { | ||
550 | 557 | |
551 | 558 | std::string prop_val = property_get(prop_name.c_str()); |
552 | 559 | 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; | |
556 | 566 | } |
557 | 567 | |
558 | 568 | dst->append(prop_val); |