Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: `rm *` count is incorrect with `setopt GLOB_DOTS`



On Fri, Apr 13, 2018 at 5:23 PM,  <zsh-workers@xxxxxxxxxxx> wrote:
>
> When I run `rm *`, zsh asks if I "want to delete all x files", where x
> is the number of files to be deleted. However, with `setopt GOB_DOTS`,
> this number appears to be two more than the actual number of files.

It's counting "." and ".." because, well, they begin with a dot.

It's actually wrong any time the directory contains files beginning
with ".", it's just LESS wrong when GLOB_DOTS.

Apologies if this gets line-folded badly:

diff --git a/Src/utils.c b/Src/utils.c
index 180693d..2a006b4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2775,10 +2775,11 @@ checkrmall(char *s)
     const int max_count = 100;
     if ((rmd = opendir(unmeta(s)))) {
     int ignoredots = !isset(GLOBDOTS);
-    /* ### TODO: Passing ignoredots here is wrong.  See workers/41672
-       aka <https://bugs.debian.org/875460>.
-     */
-    while (zreaddir(rmd, ignoredots)) {
+    char *fname;
+
+    while ((fname = zreaddir(rmd, 1))) {
+        if (ignoredots && *fname == '.')
+        continue;
         count++;
         if (count > max_count)
         break;



Messages sorted by: Reverse Date, Date, Thread, Author