From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15018 invoked by alias); 27 Jun 2015 17:02:36 -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: 35631 Received: (qmail 1530 invoked from network); 27 Jun 2015 17:02:34 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2 autolearn=ham autolearn_force=no version=3.4.0 X-Originating-IP: [80.3.228.158] X-Spam: 0 X-Authority: v=2.1 cv=dtgmcAU4 c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=1rfpljPv4H7OVQRdeawA:9 a=CjuIK1q_8ugA:10 Date: Sat, 27 Jun 2015 18:02:30 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: '>>' does not create file if set -C (noclobber) is active Message-ID: <20150627180230.5fda7e09@ntlworld.com> In-Reply-To: <558D5E34.3020505@inlv.org> References: <558B5342.2090706@inlv.org> <150624184916.ZM19079@torch.brasslantern.com> <558B65EB.3060204@inlv.org> <150625003047.ZM19218@torch.brasslantern.com> <558D5E34.3020505@inlv.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit This isn't very elegant, but nor is it obviously problematic, and it does at least draw attention to a potential issue. pws diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 2371e35..6dd2239 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1819,6 +1819,20 @@ Make the tt(echo) builtin compatible with the BSD manref(echo)(1) command. This disables backslashed escape sequences in echo strings unless the tt(-e) option is specified. ) +pindex(CLOBBER_APPEND) +pindex(NO_CLOBBER_APPEND) +pindex(CLOBBERAPPEND) +pindex(NOCLOBBERAPPEND) +cindex(clobbering, POSIX compatibility) +cindex(file clobbering, POSIX compatibility) +cindex(no clobber, POSIX compatible) +item(tt(CLOBBER_APPEND) )( +This option only applies when tt(NO_CLOBBER) (-tt(C)) is in effect. + +If this option is not set, the shell will report an error when a +append redirection (tt(>>)) is used on a file that does not already +exists. If the option is set, no error is reported. +) pindex(CONTINUE_ON_ERROR) pindex(NO_CONTINUE_ON_ERROR) pindex(CONTINUEONERROR) diff --git a/Src/exec.c b/Src/exec.c index 50a11eb..4ddfdf4 100644 --- a/Src/exec.c +++ b/Src/exec.c @@ -3315,7 +3315,8 @@ execcmd(Estate state, int input, int output, int how, int last1) fil = -1; else if (IS_APPEND_REDIR(fn->type)) fil = open(unmeta(fn->name), - (unset(CLOBBER) && !IS_CLOBBER_REDIR(fn->type)) ? + ((unset(CLOBBER) || isset(CLOBBERAPPEND)) && + !IS_CLOBBER_REDIR(fn->type)) ? O_WRONLY | O_APPEND | O_NOCTTY : O_WRONLY | O_APPEND | O_CREAT | O_NOCTTY, 0666); else diff --git a/Src/options.c b/Src/options.c index da3d830..3a0c838 100644 --- a/Src/options.c +++ b/Src/options.c @@ -110,6 +110,7 @@ static struct optname optns[] = { {{NULL, "chaselinks", OPT_EMULATE}, CHASELINKS}, {{NULL, "checkjobs", OPT_EMULATE|OPT_ZSH}, CHECKJOBS}, {{NULL, "clobber", OPT_EMULATE|OPT_ALL}, CLOBBER}, +{{NULL, "clobberappend", OPT_EMULATE|OPT_BOURNE}, CLOBBER}, {{NULL, "combiningchars", 0}, COMBININGCHARS}, {{NULL, "completealiases", 0}, COMPLETEALIASES}, {{NULL, "completeinword", 0}, COMPLETEINWORD}, diff --git a/Src/zsh.h b/Src/zsh.h index ce9b979..05efa5f 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2120,6 +2120,7 @@ enum { CHASELINKS, CHECKJOBS, CLOBBER, + CLOBBERAPPEND, COMBININGCHARS, COMPLETEALIASES, COMPLETEINWORD,