]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
Fixi caching in zsh completion (#5122)
authorАлександр Тихонов <disarmer.mk@gmail.com>
Sat, 21 Jan 2017 19:53:09 +0000 (23:53 +0400)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Sat, 21 Jan 2017 19:53:09 +0000 (14:53 -0500)
I found several issues with zsh completion code:

1. typo in cache filename: "SYS_ALL_PROPRTIES", so cache just not loading from this file
2. cache stored in one file, despite user or system mode. So it can be loaded later in wrong mode
3. most serious problem: broken logic - it retrieves cache when _cache_invalid is true

How to reproduce: type "systemctl --user status <TAB>" and you will see user units. Then press
control+C and type "systemctl --system status <TAB>" in same session and you'll see user units again

shell-completion/zsh/_systemctl.in

index d77a2df74eea84767019b578fb747d4782b53eed..553216da5e0bc5caefcab13be92738751827192a 100644 (file)
@@ -98,11 +98,11 @@ __systemctl()
 # Fills the unit list
 _systemctl_all_units()
 {
-  if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS ) &&
-    ! _retrieve_cache SYS_ALL_UNITS;
+  if ( [[ ${+_sys_all_units} -eq 0 ]] || _cache_invalid SYS_ALL_UNITS$_sys_service_mgr ) ||
+    ! _retrieve_cache SYS_ALL_UNITS$_sys_service_mgr;
   then
     _sys_all_units=( ${${(f)"$(__systemctl list-units --all)"}%% *} )
-    _store_cache SYS_ALL_UNITS _sys_all_units
+    _store_cache SYS_ALL_UNITS$_sys_service_mgr _sys_all_units
   fi
 }
 
@@ -111,14 +111,14 @@ _systemctl_really_all_units()
 {
   local -a all_unit_files;
   local -a really_all_units;
-  if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS ) &&
-    ! _retrieve_cache SYS_REALLY_ALL_UNITS;
+  if ( [[ ${+_sys_really_all_units} -eq 0 ]] || _cache_invalid SYS_REALLY_ALL_UNITS$_sys_service_mgr ) ||
+    ! _retrieve_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr;
   then
     all_unit_files=( ${${(f)"$(__systemctl list-unit-files)"}%% *} )
     _systemctl_all_units
     really_all_units=($_sys_all_units $all_unit_files)
     _sys_really_all_units=(${(u)really_all_units})
-    _store_cache SYS_REALLY_ALL_UNITS _sys_really_all_units
+    _store_cache SYS_REALLY_ALL_UNITS$_sys_service_mgr _sys_really_all_units
   fi
 }
 
@@ -330,13 +330,13 @@ _unit_types() {
 }
 
 _unit_properties() {
-  if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES ) &&
-    ! _retrieve_cache SYS_ALL_PROPERTIES;
+  if ( [[ ${+_sys_all_properties} -eq 0 ]] || _cache_invalid SYS_ALL_PROPERTIES$_sys_service_mgr ) ||
+    ! _retrieve_cache SYS_ALL_PROPERTIES$_sys_service_mgr;
   then
     _sys_all_properties=( ${${(M)${(f)"$(__systemctl show --all;
     @rootlibexecdir@/systemd --dump-configuration-items)"}##[[:alnum:]]##=*}%%=*}
     )
-    _store_cache SYS_ALL_PROPRTIES _sys_all_properties
+    _store_cache SYS_ALL_PROPERTIES$_sys_service_mgr _sys_all_properties
   fi
   _values -s , "${_sys_all_properties[@]}"
 }