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 46021
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Sun, 7 Jun 2020 10:20:37 -0700
- Cc: Peter Stephenson <p.w.stephenson@xxxxxxxxxxxx>, "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- In-reply-to: <20200607115515.6624e240@tarpaulin.shahaf.local2>
- 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> <ffd420f448c3b5372920e0a45d1a1a74ee7a541c.camel@ntlworld.com> <20200607115515.6624e240@tarpaulin.shahaf.local2>
On Sun, Jun 7, 2020 at 4:55 AM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
>
> In the clobbering open, we use O_CREAT|O_TRUNC, which means: if it
> doesn't exist, create it; if it already exists, truncate it. If some
> other process calls open() on the same file immediately after our
> open() [or subsequent write()] call returns, there's nothing we can do
> about that.
Also if another process already had the existing file open, whatever
it was doing will be lost. (Aside: If it's an NFS file, and the
other process continues writing, this often results in a block of NUL
bytes where the NFS server fills in between the two write positions.)
> As to CLOBBER_EMPTY, the situation is similar. We can call open() with
> O_CREAT but neither O_EXCL nor O_TRUNC and then fstat() the resulting
> file. The same race conditions as in the previous paragraphs exist
> here too — for example, someone could open() and write() to the file
> after we fstat() it — but we neither can nor need to do any better
> about races in this case than in the others.
This in fact avoids (or at least does a better job of avoiding) the
problem with two different write positions if some other process has
already opened the file for write.
Messages sorted by:
Reverse Date,
Date,
Thread,
Author