From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.bugs Subject: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy Date: Fri, 13 Jan 2012 09:23:57 +0200 Message-ID: <8362ggkquq.fsf@gnu.org> References: <87mx9su32g.fsf@web.de> <87sjjkfvwt.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: lo.gmane.org X-Trace: dough.gmane.org 1326439485 24954 80.91.229.12 (13 Jan 2012 07:24:45 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 13 Jan 2012 07:24:45 +0000 (UTC) Cc: 10489@debbugs.gnu.org To: Thierry Volpiatto Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Jan 13 08:24:41 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by lo.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1RlbVA-00008J-82 for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2012 08:24:40 +0100 Original-Received: from localhost ([::1]:42496 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlbV9-00011u-Og for geb-bug-gnu-emacs@m.gmane.org; Fri, 13 Jan 2012 02:24:39 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:42370) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlbV3-00011d-91 for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2012 02:24:37 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1RlbUx-00058N-BN for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2012 02:24:33 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:32877) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1RlbUx-00058I-9j for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2012 02:24:27 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1RlbVW-000137-53 for bug-gnu-emacs@gnu.org; Fri, 13 Jan 2012 02:25:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Eli Zaretskii Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 13 Jan 2012 07:25:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10489 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Original-Received: via spool by 10489-submit@debbugs.gnu.org id=B10489.13264394783996 (code B ref 10489); Fri, 13 Jan 2012 07:25:02 +0000 Original-Received: (at 10489) by debbugs.gnu.org; 13 Jan 2012 07:24:38 +0000 Original-Received: from localhost ([127.0.0.1]:55783 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RlbV8-00012O-EE for submit@debbugs.gnu.org; Fri, 13 Jan 2012 02:24:38 -0500 Original-Received: from mtaout22.012.net.il ([80.179.55.172]:61350) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1RlbV5-00012F-NY for 10489@debbugs.gnu.org; Fri, 13 Jan 2012 02:24:37 -0500 Original-Received: from conversion-daemon.a-mtaout22.012.net.il by a-mtaout22.012.net.il (HyperSendmail v2007.08) id <0LXQ0070077IKC00@a-mtaout22.012.net.il> for 10489@debbugs.gnu.org; Fri, 13 Jan 2012 09:23:52 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.124.136.230]) by a-mtaout22.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LXQ0065W77RRPC0@a-mtaout22.012.net.il>; Fri, 13 Jan 2012 09:23:52 +0200 (IST) In-reply-to: <87sjjkfvwt.fsf@gmail.com> X-012-Sender: halo1@inter.net.il X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.13 Precedence: list X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.6 (newer, 2) X-Received-From: 140.186.70.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-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Xref: news.gmane.org gmane.emacs.bugs:55668 Archived-At: > From: Thierry Volpiatto > Date: Thu, 12 Jan 2012 22:33:38 +0100 > > Hi, here a patch that should fix this. Thanks. > + (when (string= (file-name-as-directory from) > + (file-name-as-directory to)) > + (error "Can't copy to same directory")) > (let ((attrs (file-attributes from))) > (if (and recursive > (eq t (car attrs)) > @@ -1431,7 +1434,10 @@ > (marker-char (dired-file-marker from)) ; slow > (t nil)))) > (when (and (file-directory-p from) > - (file-directory-p to) > + (or (file-directory-p to) > + (string= (file-name-as-directory from) > + (file-name-as-directory > + (file-name-directory to)))) > (eq file-creator 'dired-copy-file)) > (setq to (file-name-directory to))) > (condition-case err > diff --git a/lisp/files.el b/lisp/files.el > --- a/lisp/files.el > +++ b/lisp/files.el > @@ -4928,6 +4928,9 @@ > (format "Copy directory %s to: " dir) > default-directory default-directory nil nil) > current-prefix-arg t nil))) > + (when (string= (file-name-as-directory directory) > + (file-name-as-directory newname)) > + (error "Can't copy to same directory")) > ;; If default-directory is a remote directory, make sure we find its > ;; copy-directory handler. > (let ((handler (or (find-file-name-handler directory 'copy-directory) I don't think this will solves all the use cases. File names are not strings, you cannot compare them as literal strings and hope to plumb all the leaks. Some situations which I think this patch will not handle correctly: . file names with different letter-case on a case-insensitive file system . relative vs absolute file names . file names that are hard links to the same directory (this includes the infamous 8+3 short aliases on Windows) I didn't actually try the patch, so apologies if I missed something which makes these non-issues. Thanks again for working on this.