Browse code

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

Ian Wienand authored on 2015/04/15 07:59:04
Showing 2 changed files
... ...
@@ -1621,14 +1621,38 @@ function disable_all_services {
1621 1621
 # Uses global ``ENABLED_SERVICES``
1622 1622
 # disable_negated_services
1623 1623
 function disable_negated_services {
1624
-    local tmpsvcs="${ENABLED_SERVICES}"
1624
+    local to_remove=""
1625
+    local remaining=""
1626
+    local enabled=""
1625 1627
     local service
1626
-    for service in ${tmpsvcs//,/ }; do
1628
+
1629
+    # build up list of services that should be removed; i.e. they
1630
+    # begin with "-"
1631
+    for service in ${ENABLED_SERVICES//,/ }; do
1627 1632
         if [[ ${service} == -* ]]; then
1628
-            tmpsvcs=$(echo ${tmpsvcs}|sed -r "s/(,)?(-)?${service#-}(,)?/,/g")
1633
+            to_remove+=",${service#-}"
1634
+        else
1635
+            remaining+=",${service}"
1629 1636
         fi
1630 1637
     done
1631
-    ENABLED_SERVICES=$(_cleanup_service_list "$tmpsvcs")
1638
+
1639
+    # go through the service list.  if this service appears in the "to
1640
+    # be removed" list, drop it
1641
+    for service in ${remaining//,/ }; do
1642
+        local remove
1643
+        local add=1
1644
+        for remove in ${to_remove//,/ }; do
1645
+            if [[ ${remove} == ${service} ]]; then
1646
+                add=0
1647
+                break
1648
+            fi
1649
+        done
1650
+        if [[ $add == 1 ]]; then
1651
+            enabled="${enabled},$service"
1652
+        fi
1653
+    done
1654
+
1655
+    ENABLED_SERVICES=$(_cleanup_service_list "$enabled")
1632 1656
 }
1633 1657
 
1634 1658
 # disable_service() removes the services passed as argument to the
... ...
@@ -130,7 +130,15 @@ test_disable_negated_services 'a,-a' ''
130 130
 test_disable_negated_services 'b,a,-a' 'b'
131 131
 test_disable_negated_services 'a,b,-a' 'b'
132 132
 test_disable_negated_services 'a,-a,b' 'b'
133
-
133
+test_disable_negated_services 'a,aa,-a' 'aa'
134
+test_disable_negated_services 'aa,-a' 'aa'
135
+test_disable_negated_services 'a_a, -a_a' ''
136
+test_disable_negated_services 'a-b, -a-b' ''
137
+test_disable_negated_services 'a-b, b, -a-b' 'b'
138
+test_disable_negated_services 'a,-a,av2,b' 'av2,b'
139
+test_disable_negated_services 'a,aa,-a' 'aa'
140
+test_disable_negated_services 'a,av2,-a,a' 'av2'
141
+test_disable_negated_services 'a,-a,av2' 'av2'
134 142
 
135 143
 echo "Testing is_package_installed()"
136 144