about summary refs log tree commit diff
diff options
context:
space:
mode:
authorPeter Stephenson <pws@zsh.org>2016-02-11 15:23:57 +0000
committerPeter Stephenson <pws@zsh.org>2016-02-11 15:23:57 +0000
commit6d82ce161a760af4421c1153e78741bda95bf6b6 (patch)
tree3c47d24d82c798293e4a01eba16b74527cad950b
parent10cf74deee142d1f02d12a76bc4eab2d224423f5 (diff)
downloadzsh-6d82ce161a760af4421c1153e78741bda95bf6b6.tar.gz
zsh-6d82ce161a760af4421c1153e78741bda95bf6b6.tar.xz
zsh-6d82ce161a760af4421c1153e78741bda95bf6b6.zip
37946: make rm * warnings more informative.
Now count files that would be deleted up to 100.
-rw-r--r--ChangeLog5
-rw-r--r--Src/utils.c31
2 files changed, 32 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index a549e1112..a6e3514fa 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+2016-02-11  Peter Stephenson  <p.stephenson@samsung.com>
+
+	* 37946: Src/utils.c: make rm * warnings more informative about
+	files being deleted.
+
 2016-02-09  Peter Stephenson  <p.stephenson@samsung.com>
 
 	* 37893: Doc/Zsh/builtins.yo: document behaviour of typeset -U
diff --git a/Src/utils.c b/Src/utils.c
index de4af5a51..12911d3f4 100644
--- a/Src/utils.c
+++ b/Src/utils.c
@@ -2634,13 +2634,36 @@ zsleep_random(long max_us, time_t end_time)
 int
 checkrmall(char *s)
 {
+    DIR *rmd;
+    int count = 0;
     if (!shout)
 	return 1;
-    fprintf(shout, "zsh: sure you want to delete all the files in ");
     if (*s != '/') {
-	nicezputs(pwd[1] ? pwd : "", shout);
-	fputc('/', shout);
-    }
+	if (pwd[1])
+	    s = zhtricat(pwd, "/", s);
+	else
+	    s = dyncat("/", s);
+    }
+    const int max_count = 100;
+    if ((rmd = opendir(unmeta(s)))) {
+	int ignoredots = !isset(GLOBDOTS);
+	while (zreaddir(rmd, ignoredots)) {
+	    count++;
+	    if (count > max_count)
+		break;
+	}
+	closedir(rmd);
+    }
+    if (count > max_count)
+	fprintf(shout, "zsh: sure you want to delete more than %d files in ",
+		max_count);
+    else if (count == 1)
+	fprintf(shout, "zsh: sure you want to delete the only file in ");
+    else if (count > 0)
+	fprintf(shout, "zsh: sure you want to delete all %d files in ",
+		count);
+    else
+	fprintf(shout, "zsh: sure you want to delete all the files in ");
     nicezputs(s, shout);
     if(isset(RMSTARWAIT)) {
 	fputs("? (waiting ten seconds)", shout);