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 45994
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: Any way to allow clobbering empty files when noclobber is set?
- Date: Sat, 6 Jun 2020 04:48:08 +0000
- Cc: "zsh-workers@xxxxxxx" <zsh-workers@xxxxxxx>, Martin Tournoij <martin@xxxxxxxxxx>
- In-reply-to: <CAH+w=7b9WP77s5cTBO+gszHS=WJDLXzjjQqvU-E1Jdwz_jRwQw@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> <20200604014850.52d241bd@tarpaulin.shahaf.local2> <CAH+w=7a0s5BhBWRHReD1oGkKLkxVt8rs+kZQu9Dg0-efaKuYtg@mail.gmail.com> <a36ec51a-6f76-454f-9a1a-327557de3223@www.fastmail.com> <CAH+w=7bwKvJ7F4JCu7CUuTVxivy8OScCFwN97DKnK9M9QXqVSA@mail.gmail.com> <20200605031013.16a36d31@tarpaulin.shahaf.local2> <CAH+w=7b9WP77s5cTBO+gszHS=WJDLXzjjQqvU-E1Jdwz_jRwQw@mail.gmail.com>
Bart Schaefer wrote on Fri, 05 Jun 2020 18:07 -0700:
> (Martin, if you are no longer interested in these side discussions, we
> can stop Cc'ing you.)
>
> On Thu, Jun 4, 2020 at 8:10 PM Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> >
> > Bart Schaefer wrote on Wed, 03 Jun 2020 22:00 -0700:
> > > Fair enough, although (silly example) "false > empty" would remove the
> > > file?
> >
> > Depends on whether ./empty was created by the redirection or not.
>
> Hm. That means that the following must all be preserved (in the
> parent shell, so fails for "exec command > file") all the way from the
> redirection event to the completion of the command:
> - whether the descriptor resulted from redirection
> - what kind of redirection operator was used
> - whether the appropriate clobber-related option was set at the time
> - how to identify the file we opened, in case something else renamed
> or removed it, and created another one of the same name in the
> meantime
>
> That seems at least impractical, especially the last one.
It'll just be a couple of local variables on the C stack, won't it?
For the last bullet, I suppose we could save the inode number (and
device number), but as I wrote in workers/45977, I don't see a way to
avoid a race condition.
> And what happens in the case of rename?
If the file has been renamed before we get around to unlink it, then we
won't unlink it. We won't have a choice.
> > Besides, if the redirection failed — I assume you mean the open(2)
> > failed — then isn't the unlink likely to fail as well?
>
> Open could fail because of file permissions. Unlink depends only on
> directory permissions.
>
Well, yes, but usually, if you don't have permission to read a file,
in practice you won't have permission to delete it either.
> > Okay. Is there a case where leaving around an empty file is worse than
> > removing it?
>
> IMO your examples are all too specific to warrant a generalized change
> in behavior of redirections.
Fair enough. As I said, just brainstorming.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author