From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 14137 invoked by alias); 28 Jun 2015 17:25:33 -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: 35655 Received: (qmail 7014 invoked from network); 28 Jun 2015 17:25:30 -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=MJad45tl c=1 sm=1 tr=0 a=P+FLVI8RzFchTbbqTxIDRw==:117 a=P+FLVI8RzFchTbbqTxIDRw==:17 a=NLZqzBF-AAAA:8 a=kj9zAlcOel0A:10 a=P5Q6L1DsAAAA:8 a=wzNJwVN4KSerb_PFe24A:9 a=CjuIK1q_8ugA:10 Date: Sun, 28 Jun 2015 18:19:51 +0100 From: Peter Stephenson To: zsh-workers@zsh.org Subject: Re: '>>' does not create file if set -C (noclobber) is active Message-ID: <20150628181951.569bbff2@ntlworld.com> In-Reply-To: <558F397D.9030708@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> <20150627180230.5fda7e09@ntlworld.com> <558F397D.9030708@inlv.org> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Sun, 28 Jun 2015 02:02:05 +0200 Martijn Dekker wrote: > Peter Stephenson schreef op 27-06-15 om 19:02: > > This isn't very elegant, but nor is it obviously problematic, and it > > does at least draw attention to a potential issue. > > I've tested this patch against the current git version and noticed the > following: Yep, I got throughly confused about the logic. I think this is now correct. It doesn't have to have a name with CLOBBER in it, though it does have to be related to NO_CLOBBER --- the whole point is to choose between long-standing and documented zsh behaviour, and POSIX behaviour, when you have NO_CLOBBER set. You can now also make your own decision which you want, and don't need to post messages to the list to tell us :-). I've called it APPEND_CREATE. diff --git a/Doc/Zsh/options.yo b/Doc/Zsh/options.yo index 2371e35..833c975 100644 --- a/Doc/Zsh/options.yo +++ b/Doc/Zsh/options.yo @@ -1094,10 +1094,12 @@ pindex(NOCLOBBER) cindex(clobbering, of files) cindex(file clobbering, allowing) item(tt(CLOBBER) (tt(PLUS()C), ksh: tt(PLUS()C)) )( -Allows `tt(>)' redirection to truncate existing files, -and `tt(>>)' to create files. -Otherwise `tt(>!)' or `tt(>|)' must be used to truncate a file, -and `tt(>>!)' or `tt(>>|)' to create a file. +Allows `tt(>)' redirection to truncate existing files. +Otherwise `tt(>!)' or `tt(>|)' must be used to truncate a file. + +If the option is not set, and the option tt(APPEND_CREATE) is also +not set, `tt(>>!)' or `tt(>>|)' must be used to create a file. +If either option is set, `tt(>>)' may be used. ) pindex(CORRECT) pindex(NO_CORRECT) @@ -1792,6 +1794,21 @@ enditem() subsect(Shell Emulation) startitem() +pindex(APPEND_CREATE +pindex(NO_APPEND_CREATE) +pindex(APPENDCREATE) +pindex(NOAPPENDCREATE) +cindex(clobbering, POSIX compatibility) +cindex(file clobbering, POSIX compatibility) +cindex(no clobber, POSIX compatible) +item(tt(APPEND_CREATE) )( +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 (the traditional zsh behaviour of tt(NO_CLOBBER)). If the option +is set, no error is reported (POSIX behaviour). +) pindex(BASH_REMATCH) pindex(NO_BASH_REMATCH) pindex(BASHREMATCH) diff --git a/Src/exec.c b/Src/exec.c index 39d1326..960601f 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) && unset(APPENDCREATE)) && + !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..320f46b 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, "appendcreate", OPT_EMULATE|OPT_BOURNE}, APPENDCREATE}, {{NULL, "combiningchars", 0}, COMBININGCHARS}, {{NULL, "completealiases", 0}, COMPLETEALIASES}, {{NULL, "completeinword", 0}, COMPLETEINWORD}, diff --git a/Src/zsh.h b/Src/zsh.h index ce9b979..183620f 100644 --- a/Src/zsh.h +++ b/Src/zsh.h @@ -2120,6 +2120,7 @@ enum { CHASELINKS, CHECKJOBS, CLOBBER, + APPENDCREATE, COMBININGCHARS, COMPLETEALIASES, COMPLETEINWORD,