From 2796a82ab48107d4445c03938e037e60dd1bbfa9 Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Wed, 15 Apr 2015 08:59:04 +1000 Subject: [PATCH] Fix negated services with common prefix The current sed matching mixes up common-prefix matching; e.g. "-q-lbaas,q-lbaasv2" is changed into just "v2" This is more verbose, but I think more reliable. See also Ib50f782824f89ae4eb9787f11d42416704babd90. Change-Id: I3faad0841834e24acc811c05015625cf7f848b19 --- functions-common | 32 ++++++++++++++++++++++++++++---- tests/test_functions.sh | 10 +++++++++- 2 files changed, 37 insertions(+), 5 deletions(-) diff --git a/functions-common b/functions-common index 24a462ac21..e6af662069 100644 --- a/functions-common +++ b/functions-common @@ -1621,14 +1621,38 @@ function disable_all_services { # Uses global ``ENABLED_SERVICES`` # disable_negated_services function disable_negated_services { - local tmpsvcs="${ENABLED_SERVICES}" + local to_remove="" + local remaining="" + local enabled="" local service - for service in ${tmpsvcs//,/ }; do + + # build up list of services that should be removed; i.e. they + # begin with "-" + for service in ${ENABLED_SERVICES//,/ }; do if [[ ${service} == -* ]]; then - tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g") + to_remove+=",${service#-}" + else + remaining+=",${service}" fi done - ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs") + + # go through the service list. if this service appears in the "to + # be removed" list, drop it + for service in ${remaining//,/ }; do + local remove + local add=1 + for remove in ${to_remove//,/ }; do + if [[ ${remove} == ${service} ]]; then + add=0 + break + fi + done + if [[ $add == 1 ]]; then + enabled="${enabled},$service" + fi + done + + ENABLED_SERVICES=$(_cleanup_service_list "$enabled") } # disable_service() removes the services passed as argument to the diff --git a/tests/test_functions.sh b/tests/test_functions.sh index a7914f7a1b..4ebb00085e 100755 --- a/tests/test_functions.sh +++ b/tests/test_functions.sh @@ -130,7 +130,15 @@ test_disable_negated_services 'a,-a' '' test_disable_negated_services 'b,a,-a' 'b' test_disable_negated_services 'a,b,-a' 'b' test_disable_negated_services 'a,-a,b' 'b' - +test_disable_negated_services 'a,aa,-a' 'aa' +test_disable_negated_services 'aa,-a' 'aa' +test_disable_negated_services 'a_a, -a_a' '' +test_disable_negated_services 'a-b, -a-b' '' +test_disable_negated_services 'a-b, b, -a-b' 'b' +test_disable_negated_services 'a,-a,av2,b' 'av2,b' +test_disable_negated_services 'a,aa,-a' 'aa' +test_disable_negated_services 'a,av2,-a,a' 'av2' +test_disable_negated_services 'a,-a,av2' 'av2' echo "Testing is_package_installed()"