zsh-workers
 help / color / mirror / code / Atom feed
From: Peter Stephenson <p.w.stephenson@ntlworld.com>
To: zsh-workers@sunsite.dk (Zsh hackers list)
Subject: Re: no_clobber and error conditions
Date: Wed, 10 May 2006 20:12:32 +0100	[thread overview]
Message-ID: <200605101912.k4AJCWrU004708@pwslaptop.csr.com> (raw)
In-Reply-To: Your message of "Wed, 10 May 2006 08:59:02 PDT." <060510085902.ZM11172@torch.brasslantern.com>

Bart Schaefer wrote:
> However, it appears that the error from noclobber does not "throw an
> exception," it merely causes the command to have exit status 1.
> 
> That's not consistent with csh behavior (tcsh in this sample):
> 
> [schaefer@toltec /tmp]$ ( set noclobber; echo > lockfile; echo oops )
> lockfile: File exists.
> [schaefer@toltec /tmp]$ 
> schaefer[537] ( setopt noclobber; echo > lockfile; echo oops )
> zsh: file exists: lockfile
> oops
> schaefer[538]

It is consistent with bash.  The standard just says it "shall fail".  I
couldn't see a formal definition of "fail", but it seems just to
indicate returning a non-zero status, as in

  If a command fails during word expansion or redirection, its exit status
  shall be greater than zero.

But a failure doesn't need to be atomically handled, does it?  How about
revisiting:

  echo >foo || { readonly THROW; THROW= 2>/dev/null; };

(where "readonly THROW" should be at the top of the function).  Or, of
course, use throw and catch functions:

function lock() {
  emulate -L zsh
  setopt noclobber xtrace
  integer ret=-1

  autoload -U throw catch
  while true; do
    {
       : >$1  ||  throw Exists
    } always {
      if ! catch Exists; then
        if catch ''; then
          ret=1
        else
          ret=0
        fi
      fi
    }
    (( ret >= 0 )) && return $ret
    sleep 1
  done
}

("return" in the middle of the always block doesn't work.  I can't quite
make up my mind whether to be embarrassed or not.  It depends how
seriously you take "Execution [after the always block] continues from
the result of the execution of try-list".)

-- 
Peter Stephenson <p.w.stephenson@ntlworld.com>
Web page now at http://homepage.ntlworld.com/p.w.stephenson/


      reply	other threads:[~2006-05-10 19:12 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <87r7324zyh.fsf@asfast.com>
2006-05-10 15:59 ` Bart Schaefer
2006-05-10 19:12   ` Peter Stephenson [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=200605101912.k4AJCWrU004708@pwslaptop.csr.com \
    --to=p.w.stephenson@ntlworld.com \
    --cc=zsh-workers@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).