diff options
author | Clint Adams <clint@users.sourceforge.net> | 2001-03-30 21:02:44 +0000 |
---|---|---|
committer | Clint Adams <clint@users.sourceforge.net> | 2001-03-30 21:02:44 +0000 |
commit | 7c48a9699ef4fa0d00461c5815280c681bcd5483 (patch) | |
tree | 6416199747a42dc0a25d4b7dec78dd424f381f61 /Completion | |
parent | 261193a5b7da4ba36ca146424b000aca27c69235 (diff) | |
download | zsh-7c48a9699ef4fa0d00461c5815280c681bcd5483.tar.gz zsh-7c48a9699ef4fa0d00461c5815280c681bcd5483.tar.xz zsh-7c48a9699ef4fa0d00461c5815280c681bcd5483.zip |
13860: caching layer support in _deb_packages
Diffstat (limited to 'Completion')
-rw-r--r-- | Completion/Debian/_deb_packages | 29 |
1 files changed, 26 insertions, 3 deletions
diff --git a/Completion/Debian/_deb_packages b/Completion/Debian/_deb_packages index 7973d9868..be36c817c 100644 --- a/Completion/Debian/_deb_packages +++ b/Completion/Debian/_deb_packages @@ -3,19 +3,26 @@ # Usage: _deb_packages expl... avail|installed|uninstalled _deb_packages_update_avail () { - if (( ! $+_deb_packages_cache_avail )); then + if ( [[ ${+_deb_packages_cache_avail} -eq 0 ]] || + _cache_invalid DEBS_avail ) && ! _retrieve_cache DEBS_avail; + then _deb_packages_cache_avail=( ${(f)"$(apt-cache dumpavail | awk '/^Package:/ { print $2 }')"} ) + + _store_cache DEBS_avail _deb_packages_cache_avail fi cachevar=_deb_packages_cache_avail } _deb_packages_update_installed () { - if (( ! $+_deb_packages_cache_installed )); then + if ( [[ ${+_deb_packages_cache_installed} -eq 0 ]] || + _cache_invalid DEBS_installed ) && ! _retrieve_cache DEBS_installed; + then _deb_packages_cache_installed=( ${${${(f)"$(dpkg --get-selections)"}:#*deinstall}%% *} ) + _store_cache DEBS_installed _deb_packages_cache_installed fi cachevar=_deb_packages_cache_installed } @@ -32,7 +39,12 @@ _deb_packages_update_uninstalled () { } _deb_packages () { - local command="$argv[$#]" expl cachevar pkgset + local command="$argv[$#]" expl cachevar pkgset update_policy + + zstyle -s ":completion:*:*:$service:*" cache-policy update_policy + if [[ -z "$update_policy" ]]; then + zstyle ":completion:*:*:$service:*" cache-policy _debs_caching_policy + fi [[ "$command" = (installed|uninstalled|avail) ]] || { _message "_deb_packages:unknown command: $command" @@ -54,4 +66,15 @@ _deb_packages () { _tags packages && compadd "$expl[@]" - "${(@P)cachevar}" } + _debs_caching_policy () { + # rebuild if cache is more than a week old + oldp=( "$1"(mw+1) ) + (( $#oldp )) && return 0 + + [[ /var/cache/apt/pkgcache.bin -nt "$1" || + /var/lib/dpkg/available -nt "$1" ]] + } + + + _deb_packages "$@" |