From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Tino Calancha Newsgroups: gmane.emacs.bugs Subject: bug#27496: 26.0.50; dired-do-shell-command just checks the first wildcard Date: Mon, 26 Jun 2017 19:45:13 +0900 Message-ID: <87fuen58p2.fsf@calancha-pc> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1498474060 14528 195.159.176.226 (26 Jun 2017 10:47:40 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 26 Jun 2017 10:47:40 +0000 (UTC) To: 27496@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Jun 26 12:47:36 2017 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRYN-0003VB-JQ for geb-bug-gnu-emacs@m.gmane.org; Mon, 26 Jun 2017 12:47:35 +0200 Original-Received: from localhost ([::1]:45850 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPRYS-00056f-ML for geb-bug-gnu-emacs@m.gmane.org; Mon, 26 Jun 2017 06:47:40 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44927) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPRWx-0003tN-3g for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:46:08 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWt-0002uZ-4t for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:46:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:35380) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPRWt-0002uR-0s for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:46:03 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dPRWs-0007Mo-O3 for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:46:02 -0400 X-Loop: help-debbugs@gnu.org Resent-From: Tino Calancha Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Mon, 26 Jun 2017 10:46:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: report 27496 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: patch X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.149847393628270 (code B ref -1); Mon, 26 Jun 2017 10:46:02 +0000 Original-Received: (at submit) by debbugs.gnu.org; 26 Jun 2017 10:45:36 +0000 Original-Received: from localhost ([127.0.0.1]:38057 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWR-0007Lu-Uz for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:36 -0400 Original-Received: from eggs.gnu.org ([208.118.235.92]:53810) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dPRWQ-0007Lh-3U for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:34 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWJ-0002iq-HH for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:28 -0400 Original-Received: from lists.gnu.org ([2001:4830:134:3::11]:55381) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dPRWJ-0002ik-Dh for submit@debbugs.gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:44773) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dPRWH-0003mJ-TM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:27 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dPRWD-0002h7-Vb for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:25 -0400 Original-Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:34960) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dPRWD-0002gP-OM for bug-gnu-emacs@gnu.org; Mon, 26 Jun 2017 06:45:21 -0400 Original-Received: by mail-pf0-x244.google.com with SMTP id s66so17595211pfs.2 for ; Mon, 26 Jun 2017 03:45:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=Btl5aoxlQaUvQkSFdY44iBLIYsNoabFdBEO/XGMwaT/5vZhvtDxVTFwVbha/OPbr4w cOsklD/dSDjQdlGi+Y36ergkO3lrKTJXMDHpqyJvJYMLMTm9ry3P8NUuGqB53FaZFGUG QsFOuaf/ibtdpVv8m3fK8ZGLeq8dMPBNxMPKO4pM/xr5K6cP8L5o0JsuvkzKrxig9JRd fiX/2lEbNVZ2eHDKfepvKYq2kk4V/r+NEPqWUHGmPMxMAN4eVXhNc8UJB/9tyLRU7OmE cDv8gWU+tHmzCAxS3L6Z2dZMW4B3N2D2OAffNIlKUcogn1Yb8MiWLtRozZjWEotM0OPR /hIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:message-id:from:to:subject; bh=xOfgrIrj/1b6noUy9znzZLJJWG+k8yF44AGvTuqODtY=; b=ac9lkrpSmRmOZYOEQlTh2beSfQaAJv2UeqJp1D7MBpB0RKhvjl0pYaL9LjY4KRPo0a sSt+wmRwJQKXldpocOR4Ssat0ZrsdhbkR1zglZBAT9RYDkvK0gHzTRIi5myZfWSnY2HK Iu4fbg1bcEghNKj8MN8TJZwuBXHQuGNs7I0ULffE5/l6GgCeUDWLhA8vHDTMm9H8KWNy FxDkBsw+BPguCKDJNWwqBXh3gWLu+0SIub5vpMQ/e5lhRSQe7qdowpBBYBZIjwakoF2S wBkThtLIOlhgvfmtOC1DD5Rju+nVGVH4L1mthI3Be0mI+KLHbmdvsnchaKa0RhnGudm/ 6rCg== X-Gm-Message-State: AKS2vOygG8ftIIWv8NPPsyngALusHNIV0vIFoUu5gQowPLbw+E0Vgdne aAsRJyo8x+IWLfqA X-Received: by 10.98.150.157 with SMTP id s29mr20780155pfk.172.1498473919014; Mon, 26 Jun 2017 03:45:19 -0700 (PDT) Original-Received: from calancha-pc (222.139.137.133.dy.bbexcite.jp. [133.137.139.222]) by smtp.gmail.com with ESMTPSA id e189sm21280130pfe.100.2017.06.26.03.45.17 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 26 Jun 2017 03:45:18 -0700 (PDT) X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6.x X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 208.118.235.43 X-BeenThere: bug-gnu-emacs@gnu.org List-Id: "Bug reports for GNU Emacs, the Swiss army knife of text editors" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.org gmane.emacs.bugs:133917 Archived-At: 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 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