GNU bug report logs - #27496
26.0.50; dired-do-shell-command just checks the first wildcard

Previous Next

Package: emacs;

Reported by: Tino Calancha <tino.calancha <at> gmail.com>

Date: Mon, 26 Jun 2017 10:46:02 UTC

Severity: minor

Tags: patch

Found in version 26.0.50

Done: Tino Calancha <tino.calancha <at> gmail.com>

Bug is archived. No further changes may be made.

To add a comment to this bug, you must first unarchive it, by sending
a message to control AT debbugs.gnu.org, with unarchive 27496 in the body.
You can then email your comments to 27496 AT debbugs.gnu.org in the normal way.

Toggle the display of automated, internal messages from the tracker.

View this report as an mbox folder, status mbox, maintainer mbox


Report forwarded to bug-gnu-emacs <at> gnu.org:
bug#27496; Package emacs. (Mon, 26 Jun 2017 10:46:02 GMT) Full text and rfc822 format available.

Acknowledgement sent to Tino Calancha <tino.calancha <at> gmail.com>:
New bug report received and forwarded. Copy sent to bug-gnu-emacs <at> gnu.org. (Mon, 26 Jun 2017 10:46:02 GMT) Full text and rfc822 format available.

Message #5 received at submit <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: bug-gnu-emacs <at> gnu.org
Subject: 26.0.50; dired-do-shell-command just checks the first wildcard
Date: Mon, 26 Jun 2017 19:45:13 +0900
Severity: minor
Tags: patch

emacs -Q:
;; Evaluate following form.
(let ((foo (make-temp-file "foo" 'dir))
      (bar (make-temp-file "bar" 'dir)))
  (dired foo)
  (dired-up-directory)
  (revert-buffer)
  (dired-do-shell-command
   (format "cp -r ? %s/?" bar) nil (dired-get-marked-files t nil)))

;; Should ask confirmation because "/?".

If we change the last line to:
(format "cp -r ./? %s/?" bar) nil (dired-get-marked-files t nil)))
then it asks confirmation because "./?".


--8<-----------------------------cut here---------------start------------->8---
commit dd809606eefea96a034eb4fe8da237003321ffd3
Author: Tino Calancha <tino.calancha <at> gmail.com>
Date:   Mon Jun 26 19:16:57 2017 +0900

    Ask confirmation for all suspicious wildcards
    
    * lisp/dired-aux.el (dired-do-shell-command): Check that all
    the wildcards are right.  Otherwise, ask fo confirmation (Bug#27496).

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index 121bebeb65..f257a454f9 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -704,31 +704,41 @@ dired-do-shell-command
       (dired-read-shell-command "! on %s: " current-prefix-arg files)
       current-prefix-arg
       files)))
-  (let* ((on-each (not (string-match-p dired-star-subst-regexp command)))
-	 (no-subst (not (string-match-p dired-quark-subst-regexp command)))
-	 (star (string-match-p "\\*" command))
-	 (qmark (string-match-p "\\?" command))
-         ;; Get confirmation for wildcards that may have been meant
-         ;; to control substitution of a file name or the file name list.
-         (ok (cond ((not (or on-each no-subst))
-	            (error "You can not combine `*' and `?' substitution marks"))
-	           ((and star on-each)
-	            (y-or-n-p (format-message
-			       "Confirm--do you mean to use `*' as a wildcard? ")))
-	           ((and qmark no-subst)
-	            (y-or-n-p (format-message
-			       "Confirm--do you mean to use `?' as a wildcard? ")))
-	           (t))))
-    (when ok
-      (if on-each
-	  (dired-bunch-files (- 10000 (length command))
-	                     (lambda (&rest files)
-	                       (dired-run-shell-command
-                                (dired-shell-stuff-it command files t arg)))
-	                     nil file-list)
-	;; execute the shell command
-	(dired-run-shell-command
-	 (dired-shell-stuff-it command file-list nil arg))))))
+  (cl-flet ((need-confirm-p
+             (cmd str)
+             (let ((res cmd)
+                   (str (regexp-quote str))
+                   (regexp (if (string= str "?")
+                               dired-quark-subst-regexp
+                             dired-star-subst-regexp)))
+               ;; Drop all ? and * surrounded by spaces.
+               (while (and (string-match-p str res)
+                           (string-match regexp res))
+                 (setq res (replace-match "" t t res 0)))
+               (string-match-p str res))))
+    (let* ((on-each (not (string-match-p dired-star-subst-regexp command)))
+	   (no-subst (not (string-match-p dired-quark-subst-regexp command)))
+           ;; Get confirmation for wildcards that may have been meant
+           ;; to control substitution of a file name or the file name list.
+           (ok (cond ((not (or on-each no-subst))
+	              (error "You can not combine `*' and `?' substitution marks"))
+	             ((need-confirm-p command "*")
+	              (y-or-n-p (format-message
+			         "Confirm--do you mean to use `*' as a wildcard? ")))
+	             ((need-confirm-p command "?")
+	              (y-or-n-p (format-message
+			         "Confirm--do you mean to use `?' as a wildcard? ")))
+	             (t))))
+      (when ok
+        (if on-each
+	    (dired-bunch-files (- 10000 (length command))
+	                       (lambda (&rest files)
+	                         (dired-run-shell-command
+                                  (dired-shell-stuff-it command files t arg)))
+	                       nil file-list)
+	  ;; execute the shell command
+	  (dired-run-shell-command
+	   (dired-shell-stuff-it command file-list nil arg)))))))
 
 ;; Might use {,} for bash or csh:
 (defvar dired-mark-prefix ""
--8<-----------------------------cut here---------------end--------------->8---

In GNU Emacs 26.0.50 (build 9, x86_64-pc-linux-gnu, GTK+ Version 3.22.11)
 of 2017-06-26 built
Repository revision: 1771d9b8082cf967e3f8b6a436d8766560be9e8d




Reply sent to Tino Calancha <tino.calancha <at> gmail.com>:
You have taken responsibility. (Sun, 02 Jul 2017 13:14:03 GMT) Full text and rfc822 format available.

Notification sent to Tino Calancha <tino.calancha <at> gmail.com>:
bug acknowledged by developer. (Sun, 02 Jul 2017 13:14:04 GMT) Full text and rfc822 format available.

Message #10 received at 27496-done <at> debbugs.gnu.org (full text, mbox):

From: Tino Calancha <tino.calancha <at> gmail.com>
To: 27496-done <at> debbugs.gnu.org
Subject: Re: bug#27496: 26.0.50;
 dired-do-shell-command just checks the first wildcard
Date: Sun, 02 Jul 2017 22:13:34 +0900
Tino Calancha <tino.calancha <at> gmail.com> writes:

> emacs -Q:
> ;; Evaluate following form.
> (let ((foo (make-temp-file "foo" 'dir))
>       (bar (make-temp-file "bar" 'dir)))
>   (dired foo)
>   (dired-up-directory)
>   (revert-buffer)
>   (dired-do-shell-command
>    (format "cp -r ? %s/?" bar) nil (dired-get-marked-files t nil)))
>
> ;; Should ask confirmation because "/?".
>
> If we change the last line to:
> (format "cp -r ./? %s/?" bar) nil (dired-get-marked-files t nil)))
> then it asks confirmation because "./?".
Fixed in master branch as commit
6e39940adba7b96dfe520caa52a1b92a1a84a84f




bug archived. Request was from Debbugs Internal Request <help-debbugs <at> gnu.org> to internal_control <at> debbugs.gnu.org. (Mon, 31 Jul 2017 11:24:05 GMT) Full text and rfc822 format available.

This bug report was last modified 7 years and 122 days ago.

Previous Next


GNU bug tracking system
Copyright (C) 1999 Darren O. Benham, 1997,2003 nCipher Corporation Ltd, 1994-97 Ian Jackson.