Zsh Mailing List Archive
Messages sorted by:
Re: Any way to allow clobbering empty files when noclobber is set?
- X-seq: zsh-workers 45992
- From: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- To: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Fri, 5 Jun 2020 18:41:35 -0700
- Cc: Martin Tournoij <martin@xxxxxxxxxx>
- In-reply-to: <CAN=4vMoC8aNBz=ZAW-BdA9W6MaBXN3SNBPpZZQobVRwjUg2wGQ@mail.gmail.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> <CAN=4vMoC8aNBz=ZAW-BdA9W6MaBXN3SNBPpZZQobVRwjUg2wGQ@mail.gmail.com>
On Thu, Jun 4, 2020 at 9:39 PM Roman Perepelitsa
> write() print -rn -- $1
> rm -f foo
> write hello >foo &
> write bye >foo &
> With regular no_clobber it has the following guarantees:
> 1. `write` is executed exactly once
> 2. once `wait` completes, `foo` contains either "hello" or "bye"
I don't think that's the intended typical usage of noclobber. It's
not set by default, and it can't have any effect outside the local
shell. It's meant to keep you from making silly mistakes when
interacting with the interpreter, not as a concurrent programming
> Is there a way to provide these guarantees with clobber_empty?
With clobber, you have #2, but not #1, so I think we should focus on
whether clobber_empty can guarantee #2. If you want #1, there are
other ways (but I suspect it arises from the implementation of #2 even
I think the answer is that #2 can be guaranteed if and only if
fcntl()-based locking can be applied, or some equivalent kernel
mechanism such that no more than closing of the (last dup of the)
descriptor is necessary to release the lock. The steps would have to
1. Open the file for write without truncate.
2. Attempt lock, non-blocking, and immediately close/fail if not locked.
3. Check for zero size, and immediately unlock/close/fail when nonzero.
4. Return the locked descriptor.
Messages sorted by: