Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [Bug] incorrect warning when I type rm /*
- X-seq: zsh-workers 46172
- From: Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx>
- To: Mikael Magnusson <mikachu@xxxxxxxxx>
- Subject: Re: [Bug] incorrect warning when I type rm /*
- Date: Wed, 1 Jul 2020 12:50:10 +0000
- Cc: Jonas Bräutigam <jonas@xxxxxxxxxxxxxx>, zsh-workers@xxxxxxx
- In-reply-to: <CAHYJk3SYk1yJyf9eoUwouyfZ924=kC-S2+YpT286_Y=BwU4xEA@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: <7438d554-ae4d-01c9-84c1-993227efd6f4@braeutigamj.de> <20200701110025.38f498d5@tarpaulin.shahaf.local2> <CAHYJk3SYk1yJyf9eoUwouyfZ924=kC-S2+YpT286_Y=BwU4xEA@mail.gmail.com>
- Sender: zsh-workers@xxxxxxx
Mikael Magnusson wrote on Wed, 01 Jul 2020 13:33 +0200:
> On 7/1/20, Daniel Shahaf <d.s@xxxxxxxxxxxxxxxxxx> wrote:
> > Jonas Bräutigam wrote on Wed, 01 Jul 2020 12:02 +0200:
> >> Hello,
> >>
> >> these days I wrote a command wrong. Instead of
> >>
> >> "$ rm ./*" <- deleting in the current directory
> >>
> >> I wrote:
> >>
> >> "$ rm /*" <- deleting in the root path "/"
> >>
> >> zsh warn me with:
> >>
> >> "zsh: sure you want to delete all 4 files in /home/[user]/Downloads
> >> [yn]?"
> >>
> >> After I typed "y", it tried to delete the files in "/".
> >>
> >> So the correct warning should be:
> >>
> >> "zsh: sure you want to delete all X files in / [yn]?"
> >>
> >>
> >> I use debian 10.4 with no "rm"-specifiy plugin.
> >>
> >>
> >> Whatch out If you try it! :D
> >
> > Thanks; it's a path arithmetic edge case:
> >
> > diff --git a/Src/exec.c b/Src/exec.c
> > index 045b5d2b9..7120a2c34 100644
> > --- a/Src/exec.c
> > +++ b/Src/exec.c
> > @@ -3401,7 +3401,7 @@ execcmd_exec(Estate state, Execcmd_params eparams,
> > int rmall;
> >
> > s[l - 2] = 0;
> > - rmall = checkrmall(s);
> > + rmall = checkrmall(l == 2 ? "/" : s);
> > s[l - 2] = t;
> >
> > if (!rmall) {
> >
> > The "Is the dir empty?" logic likewise operated on $PWD rather than /,
> > so if someone runs «rm /*» as root in an empty directory, the
> > RM_STAR_SILENT confirmation prompt would not appear at all.
> >
> > I haven't figured out how to write a test for this (short of using
> > expect(1) or so).
>
> zpty_start and variants as in W02jobs, X02zlevi and others?
Thanks for the pointer. I'll look when I have time, but if anyone can
beat me to it, please do.
Cheers,
Daniel
Messages sorted by:
Reverse Date,
Date,
Thread,
Author