Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: [PATCH] Completion: _opkg: Support gain-privileges

dana wrote on Sat, Jan 12, 2019 at 13:08:30 -0600:
> On 12 Jan 2019, at 11:10, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >I don't think so.  Even an "empty" result could be expensive to compute:
> >for example, it might require a network round-trip.  I think _opkg
> >shouldn't call _store_cache when _call_program returns non-zero.
> Well, i think that's effectively the same thing in this case and certain
> others i'm imagining. (Or at least i assume so; there's not really any
> documentation for opkg that i'm aware of, so who knows what actually causes it
> to return non-zero.) Just felt like it might save some boiler-plate, which the
> caching logic is extremely heavy in already, to have a standard option handle
> it. I can just add the guard to each _store_cache call myself, though, obv

Sorry, I thought you meant making that the default behaviour.  My bad.

I don't think expecting callers to check the exit code of commands they
call is an unusual or onerous requirement, not that it adds much

diff --git a/Completion/Linux/Command/_opkg b/Completion/Linux/Command/_opkg
index d64567681..deeb766d9 100644
--- a/Completion/Linux/Command/_opkg
+++ b/Completion/Linux/Command/_opkg
@@ -181,12 +181,11 @@ _opkg_pkg_all() {
   copts=( "$@" )
   { (( ! $#_opkg_cache_pkg_all )) || _cache_invalid opkg-pkg-all } &&
-  ! _retrieve_cache opkg-pkg-all && {
-    _opkg_cache_pkg_all=( ${(f)"$( _call_program pkg-all ${svc:-opkg} list )"} )
+  _retrieve_cache opkg-pkg-all || if _opkg_cache_pkg_all=( ${(f)"$( _call_program pkg-all ${svc:-opkg} list )"} ); then
     _opkg_cache_pkg_all=( ${(@)_opkg_cache_pkg_all##[[:space:]]*} )
     _opkg_cache_pkg_all=( ${(@)_opkg_cache_pkg_all%%[[:space:]]*} )
     _store_cache opkg-pkg-all _opkg_cache_pkg_all
-  }
+  fi
   (( $#upd )) && return 0
   (( $#_opkg_cache_pkg_all )) || {

But all that said, if the proposed new --option would be useful to many
callers, then of course we could/should add it.



Messages sorted by: Reverse Date, Date, Thread, Author