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 45977
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Roman Perepelitsa <roman.perepelitsa@xxxxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Fri, 5 Jun 2020 02:07:48 +0000
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>, Martin Tournoij <martin@xxxxxxxxxx>
- In-reply-to: <CAN=4vMqBCZqD04QO-hw0DwipmCVkdq+QNOEGNaSEfNxyRBqiiw@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>
Roman Perepelitsa wrote on Thu, 04 Jun 2020 07:41 +0200:
> The regular noclobber can use O_CREAT | O_EXCL to avoid races. How
> would any of the proposed modifications work? That is, how to
> implement unlink-if-empty without ever unlinking non-empty files?
I don't think that's possible: it'd require an atomic
stat-and-conditionally-unlink operation, and I don't think there's
a syscall for this. fstatat(2)-then-unlinkat(2) gets close, but it's
still racy.
Good point.
> Or how to implement clobber-if-empty without ever clobbering non-empty
> files?
By using a non-clobbering open(), then calling fstat() on the open fd.
If it's zero length, just carry on. If it's not zero length, close()
it and report an error.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author