Zsh Mailing List Archive
Messages sorted by:
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: <email@example.com>
- List-help: <mailto:firstname.lastname@example.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:email@example.com>
- List-unsubscribe: <mailto:firstname.lastname@example.org>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CGME20200603020919eucas1p13e26ebcbb335784d14bfb97b137f385a@eucas1p1.samsung.com> <email@example.com> <94e73ebcf39d4d3f9c7ae257b1d75d16@CAMSVWEXC01.scsc.local> <CAH+w=7YpQ3CcsMhAvztGHx19FnALBV349RAz4p8iuB+_8AnsxQ@mail.gmail.com> <CAN=4vMqBCZqD04QO-hw0DwipmCVkdq+QNOEGNaSEfNxyRBqiiw@mail.gmail.com> <firstname.lastname@example.org> <email@example.com> <firstname.lastname@example.org> <email@example.com> <CAN=4vMrtTugN6gBmC1A75m9Q2xLDuEzbf2sBacZNgAKcSoa6firstname.lastname@example.org> <CAH+w=7bEkZ10xqQcXSyqeJQHVLT4VrLAOMttC-2OKnTDiFNQdA@mail.gmail.com> <email@example.com> <firstname.lastname@example.org>
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: