Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: [Patch] No warnings for `rm /*`
- X-seq: zsh-workers 38351
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
- Subject: Re: [Patch] No warnings for `rm /*`
- Date: Tue, 26 Apr 2016 20:08:48 +0200
- Cc: zsh workers <zsh-workers@xxxxxxx>
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc; bh=PTk3I1cKtRdPHQyEj26AC+CbGOow0nGhn7npJT8unQs=; b=R4JnNByRoKawo2PE/j+aYPG0GDgQ+P+e0uVVfPdL1RAZNYLcvXctqv/3nLu2yyDxaR U+IoirX9MqAxaWv+yi49T2FStKNFa/WKXoN0mDjofWNuKZER9L/gpjIem923qowanavN x0Qh8shlOpeTRST9L6gP49FZcwXiKlNuuT5IqCT5zdbOApRXKCa75zYWyq811PqYatNb gHqdhPhzCbmMsfygBVuFjxyQoOrB28VxHGXw0hX298ZzjVnKXIGqFOHwAzAtzC6pPdDJ vtkc9kxfk4SHr0Xux796CdLtEBtKcM+qBhHHcyUUeyv3CyibM1y+lh6dXr0whSJTMeDm Bxgg==
- In-reply-to: <160426103624.ZM11049@torch.brasslantern.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>
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
- References: <CAN3Cs_H0Uz8c7Du53UfvoRcob5zcU8KkNeqHn6vVGaguxNHK9A@mail.gmail.com> <160426103624.ZM11049@torch.brasslantern.com>
On Tue, Apr 26, 2016 at 7:36 PM, Bart Schaefer
<schaefer@xxxxxxxxxxxxxxxx> wrote:
> On Apr 26, 10:31am, Glenn Smith wrote:
> } Subject: [Patch] No warnings for `rm /*`
> }
> } I discovered that zsh warns in every case except `rm /*`.
>
> Thanks. I think the following simpler patch does the same.
>
> diff --git a/Src/exec.c b/Src/exec.c
> index 50eff72..2dcd5bc 100644
> --- a/Src/exec.c
> +++ b/Src/exec.c
> @@ -2902,11 +2902,11 @@ execcmd(Estate state, int input, int output, int how, int last1)
> if (s[0] == Star && !s[1]) {
> if (!checkrmall(pwd))
> uremnode(args, node);
> - } else if (l > 2 && s[l - 2] == '/' && s[l - 1] == Star) {
> + } else if (l >= 2 && s[l - 2] == '/' && s[l - 1] == Star) {
> char t = s[l - 2];
>
> s[l - 2] = 0;
> - if (!checkrmall(s))
> + if (!checkrmall(*s ? s : "/"))
> uremnode(args, node);
> s[l - 2] = t;
> }
>
>
> As an aside:
>
> % rm /nonexistentdir/*
> zsh: sure you want to delete all the files in /nonexistentdir [yn]?
>
> Seems like we could detect when opendir() fails with ENOENT and skip
> the prompt, but maybe there are cases of race condition (directory is
> created after I type "rm ..." but before /bin/rm is executed?) where
> the default answer of "y" would be incorrect.
This is pretty contrived, but it's not even a race condition.
% mkdir /tmp/r; rm /tmp/r/.(e:'echo hello; touch $REPLY/foo:') /tmp/r/*
zsh: sure you want to delete all the files in /tmp/r [yn]? y
hello
rm: cannot remove '/tmp/r/.': Is a directory
removed '/tmp/r/foo'
--
Mikael Magnusson
Messages sorted by:
Reverse Date,
Date,
Thread,
Author