Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Possible bug: HASH_CMDS has no observable effect
- X-seq: zsh-workers 47375
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Subject: Re: Possible bug: HASH_CMDS has no observable effect
- Date: Sat, 12 Sep 2020 13:41:34 -0700
- Archived-at: <https://zsh.org/workers/47375>
- Archived-at: <http://www.zsh.org/sympa/arcsearch_id/zsh-workers/2020-09/CAH%2Bw%3D7aBwDz_Uo4r2ohv9wLBpeHna2C9g0QGN5FsXmqs8Hh2CA%40mail.gmail.com>
- Authentication-results: zsh.org; iprev=pass (mail-oi1-f180.google.com) smtp.remote-ip=209.85.167.180; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none
- Cc: Zsh hackers list <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=E4ynvyJEJRQOxTbIuZgehyg5ziuPUZ79VtTzcLg2bIc=; b=sle9UQTnff8fp0rXkcy3let2PX4Vd51ETdX4Qd/6aAJZLxw02UNKasBmI1fuCMD3VD A2Z+yEMZVJEROsVuOfmfcp4VaPWxk7rZT9pXUlF40hSI6czmF/vkIJYrGuXvpvZSaQCJ kVT7xwmydJiX375Miayi3/69VJYNf2NGiNiG+MnlPvGZ25+PPEAtE904H2RRyg0F0r7l xFIuaRnv4Ayecjzfsp/ngBMPnZAoz5ULdoP3s1PGftJ7wfoGVJAym8Wi69IaIm3cLWul ISnQVi+1pa6f7dLCvLtQsYGS78udMHntt/S9dSKHdXC01VPI9c0jZwrAXeqH3OxUcgYv SBpw==
- In-reply-to: <CAN=4vMr0ucdLxfb+GMevBVT-=u1oNRr+Tc9EEVKizkeQC5tL7A@mail.gmail.com>
- List-archive: <http://www.zsh.org/sympa/arc/zsh-workers>
- List-help: <mailto:sympa@zsh.org?subject=help>
- List-id: <zsh-workers.zsh.org>
- List-owner: <mailto:zsh-workers-request@zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-subscribe: <mailto:sympa@zsh.org?subject=subscribe%20zsh-workers>
- List-unsubscribe: <mailto:sympa@zsh.org?subject=unsubscribe%20zsh-workers>
- References: <CAN=4vMqM-2Vu0n+QTbA9B_9z=3DKDdiOKbDRRaGGOG2rbY7-jA@mail.gmail.com> <20200911144852.GA1669764@fullerene.field.pennock-tech.net> <CAN=4vMrFhmKitKbdPdabZ1Ey9cjmEf62GVaGVMxn6T9AjZVc8Q@mail.gmail.com> <20200911161000.GA1679994@fullerene.field.pennock-tech.net> <CAN=4vMq-prFqopCW8apuYO8YUnuKL8G=WX+jBXFwgiFkfY=5Pw@mail.gmail.com> <CAH+w=7Y2VQpidVcinSXkQQqng0XjOwYtWL7a8jiYFx+te7fQCw@mail.gmail.com> <CAN=4vMrC2QjfxWaPUE9QS9tENBu=7BB=Hmp5rY6SaFahFThq=Q@mail.gmail.com> <CAH+w=7YDbOLz8Vp9v1tuweX9rGynS19GQ3FDiSryvqX=iz2sNA@mail.gmail.com> <CAN=4vMr0ucdLxfb+GMevBVT-=u1oNRr+Tc9EEVKizkeQC5tL7A@mail.gmail.com>
- Sender: zsh-workers-request@xxxxxxx
On Sat, Sep 12, 2020 at 1:49 AM Roman Perepelitsa
<roman.perepelitsa@xxxxxxxxx> wrote:
>
> On Sat, Sep 12, 2020 at 10:35 AM Bart Schaefer
> <schaefer@xxxxxxxxxxxxxxxx> wrote:
> > The whole search-and-cache process is
> > short-circuited.
>
> Doesn't this search happen anyway? When I type `rsync`, it gets
> resolved as /usr/bin/rsync and gets executed. This requires searching
> for rsync in all path directories.
The cache is a mapping from command names to locations. So, if
"rsync" is in the cache, then the value of that cache entry is
"/usr/bin/rsync" and zsh just executes that without scanning the path
again. Conversely if HASH_DIRS is set and "rsync" is NOT in the
cache, but everything else from /usr/bin IS in the cache (as a
byproduct of some previous search), zsh reports command not found,
again without re-scanning the path.
HASH_DIRS is done incrementally, e.g., if your path is "/bin:/usr/bin"
and you first execute a command from /bin, zsh only populates the
cache with commands in /bin, and remembers that it has not looked in
/usr/bin yet. If you then execute "rsync", a cache miss causes
HASH_DIRS to scan /usr/bin, add everything there to the cache, and
execute /usr/bin/rsync.
Eventually every directory in the path will have been scanned, and
cache misses become immediately "not found". If HASH_DIRS is not set
(but HASH_CMDS is).
> I believe this is done in execute()
> in Src/exec.c. Wouldn't it be better to search for `rsync` in the
> parent shell (before forking) and hash the result?
That's exactly how it works. The search in execute() is only done if
an absolute file location for the command isn't provided by the
parent, which only occurs if HASH_CMDS is not set.
This does mean that if a command is removed from (or moved within) the
path, execute() will be handed an invalid file location and will fail.
Again, for most users this never happens.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author