Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: Any way to allow clobbering empty files when noclobber is set?
- X-seq: zsh-workers 46010
- From: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Sat, 06 Jun 2020 17:24:14 +0100
- In-reply-to: <CAH+w=7bEkZ10xqQcXSyqeJQHVLT4VrLAOMttC-2OKnTDiFNQdA@mail.gmail.com>
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20200603020919eucas1p13e26ebcbb335784d14bfb97b137f385a@eucas1p1.samsung.com> <89aed74d-db7b-47ad-b218-8158838049e9@www.fastmail.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <CAH+w=7YpQ3CcsMhAvztGHx19FnALBV349RAz4p8iuB+_8AnsxQ@mail.gmail.com> <CAN=4vMqBCZqD04QO-hw0DwipmCVkdq+QNOEGNaSEfNxyRBqiiw@mail.gmail.com> <20200605020748.635b9bb3@tarpaulin.shahaf.local2> <1941572212.466119.1591360860372@mail2.virginmedia.com> <e7f7dfe2-eb4a-457b-85fb-091935a74c0e@www.fastmail.com> <13acd486e6457c1f708304026c3e1b59521ad328.camel@ntlworld.com> <CAN=4vMrtTugN6gBmC1A75m9Q2xLDuEzbf2sBacZNgAKcSoa6-w@mail.gmail.com> <CAH+w=7bEkZ10xqQcXSyqeJQHVLT4VrLAOMttC-2OKnTDiFNQdA@mail.gmail.com>
On Sat, 2020-06-06 at 08:24 -0700, Bart Schaefer wrote:
> Just to clarify: O_CREAT|O_EXCL is actually the NO_clobber-ing open.
> The clobbering open is just to open it for writing if allowed to. and
> start scribbling over whatever is there.
You're right; in the hypothesised case, the file already exists and
this pair of options is documented to fail in that case.
I think the O_TRUNC is therefore the crucial one in our normal clobbering
open, right?
/* If clobbering, just open. */
if (isset(CLOBBER) || IS_CLOBBER_REDIR(f->type))
return open(unmeta(f->name),
O_WRONLY | O_CREAT | O_TRUNC | O_NOCTTY, 0666);
We'll truncate at that point, then start writing. That's the best
we can do. If anyone else is also writing to at *at that point*
--- out of luck, only file locking will help.
> Consequently we should be looking at this as an entirely interactive
> user DWIM feature, and choosing how to implement (or not to) based on
> that.
Yes, I certainly agree with that.
pws
Messages sorted by:
Reverse Date,
Date,
Thread,
Author