From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15854 invoked by alias); 27 Feb 2012 16:42:56 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: X-Seq: 30277 Received: (qmail 1206 invoked from network); 27 Feb 2012 16:42:55 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,FREEMAIL_FROM,NML_ADSP_CUSTOM_MED,RCVD_IN_DNSWL_LOW, T_DKIM_INVALID autolearn=no version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.google.com designates 209.85.214.171 as permitted sender) Received-SPF: pass (google.com: domain of mikachu@gmail.com designates 10.182.174.101 as permitted sender) client-ip=10.182.174.101; Authentication-Results: mr.google.com; spf=pass (google.com: domain of mikachu@gmail.com designates 10.182.174.101 as permitted sender) smtp.mail=mikachu@gmail.com; dkim=pass header.i=mikachu@gmail.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=m8sRVOBkhKkQQ+f5t7/leKvxnwz8MhFDQg095r/wpcU=; b=DpJNT2j7rIKB6y3OJjFC0y1cCaILVv2mAXWS97mmPsTRSK2TqNg9mNYK+QH/BFzoT6 axyT6HvTBaAj6ipjCH5LkQlXIZJhKEp1X6XVCmdJhscVyY8F1atNHnbltZywAKMR80tQ h1/3H6uJSG/NwdMLjpRRSWBZ3bTi1og07vttQ= MIME-Version: 1.0 In-Reply-To: <1330358932.36076.YahooMailClassic@web29706.mail.ird.yahoo.com> References: <1330281433-23949-1-git-send-email-mikachu@gmail.com> <1330358932.36076.YahooMailClassic@web29706.mail.ird.yahoo.com> Date: Mon, 27 Feb 2012 17:36:57 +0100 Message-ID: Subject: Re: PATCH: Fix _file_descriptors From: Mikael Magnusson To: Oliver Kiddle Cc: zsh-workers@zsh.org Content-Type: text/plain; charset=UTF-8 On 27 February 2012 17:08, Oliver Kiddle wrote: > --- On Sun, 26/2/12, Mikael Magnusson wrote: > >> I noticed file descriptor completion >> didn't work, with the verbose style set >> because when this is run, >> fds=( /dev/fd/<0-9>(N:t) ) >> the /dev/fd dir is open while the glob is performed, which >> results in >> a spurious entry in the result, which then cannot be >> dereferenced. The >> result is that the list array is not aligned to the fds >> array (and also >> an error message is output), and an fd that doesn't exist is >> completed. > > I'm not sure what you mean by "cannot be dereferenced". The link does not exist, so you cannot lstat it. > In any case, this whole function can be simplified by using the newish :A modifier. :A doesn't do anything useful for fds that point to things like pipe:[21325192] or 'file (deleted)'. (nor does (:a)). % echo /proc/$$/fd/2(:A); zstat +link /proc/$$/fd/2 /proc/3555/fd/2 /tmp/foo/test (deleted) % echo /proc/$$/fd/3(:A); zstat +link /proc/$$/fd/3 /proc/3555/fd/3 socket:[219517545] (We could also compare with ztcp -L before checking the symlinks, etc.) > Also, I'm fairly certain that it is intentional that this function only completes file descriptors from 0 - 9. I'm not, the code was originally a loop over {0..9} and probably the 9 was just some arbitrary low number. What reason could there possibly be to do this? > With :A, assigning fds can just be: > > fds=( /dev/fd/<0-9>(e,'[[ $REPLY:A != /proc/$$/fd ]]',) ) > > It's probably best to build up list then with a for loop after checking the style but again :A can be used instead of trying the three old mechanisms. As I noted originally, the problem with this is that there will be one link in $fds that doesn't exist when you try to build up the list array. > Another approach would be to use a subshell to open the directory: > fds=( $(print /proc/$$/fd/<0-9>(N:t)) ) > But I think there are some platforms that have /dev/fd but not /proc/$$/fd. These should still work, as the fallback still uses /dev/fd. I guess we could try both for the verbose style too though. -- Mikael Magnusson