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, 24 Feb 2012 11:19:04 +0200 Message-ID: <834nugtwqf.fsf@gnu.org> References: <87mx9su32g.fsf@web.de> <87pqekopb5.fsf@gmail.com> <87hazwoost.fsf@gmail.com> <87ty3w9639.fsf@gmx.de> <8762gckckt.fsf@gmail.com> <87pqek9269.fsf@gmx.de> <87r4z0yqfx.fsf@gmail.com> <871uqzn3bc.fsf@gmx.de> <871uqz651u.fsf@gmx.de> <87pqd89lh4.fsf@gmail.com> <87mx8b3nvb.fsf@gmail.com> <87pqd6wnvv.fsf@gmail.com> <87d395y1w0.fsf@gmail.com> <87zkc8x04p.fsf@gmail.com> <87vcmwwvk7.fsf@gmail.com> Reply-To: Eli Zaretskii NNTP-Posting-Host: plane.gmane.org X-Trace: dough.gmane.org 1330075313 11176 80.91.229.3 (24 Feb 2012 09:21:53 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 24 Feb 2012 09:21:53 +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 Feb 24 10:21:52 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([140.186.70.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S0rLb-00027u-QM for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Feb 2012 10:21:52 +0100 Original-Received: from localhost ([::1]:35658 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rLa-0004qG-U9 for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Feb 2012 04:21:50 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:60651) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rLS-0004q0-87 for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:21:49 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0rLM-0007wB-Bi for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:21:42 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49772) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rLM-0007vs-4N for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:21:36 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1S0rNh-0000Cc-MM for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:24:01 -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, 24 Feb 2012 09:24:01 +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: patch Original-Received: via spool by 10489-submit@debbugs.gnu.org id=B10489.1330075423753 (code B ref 10489); Fri, 24 Feb 2012 09:24:01 +0000 Original-Received: (at 10489) by debbugs.gnu.org; 24 Feb 2012 09:23:43 +0000 Original-Received: from localhost ([127.0.0.1]:53395 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S0rNO-0000C5-LO for submit@debbugs.gnu.org; Fri, 24 Feb 2012 04:23:43 -0500 Original-Received: from mtaout23.012.net.il ([80.179.55.175]:61330) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S0rNM-0000Bd-Ap for 10489@debbugs.gnu.org; Fri, 24 Feb 2012 04:23:42 -0500 Original-Received: from conversion-daemon.a-mtaout23.012.net.il by a-mtaout23.012.net.il (HyperSendmail v2007.08) id <0LZW00E004LODI00@a-mtaout23.012.net.il> for 10489@debbugs.gnu.org; Fri, 24 Feb 2012 11:21:00 +0200 (IST) Original-Received: from HOME-C4E4A596F7 ([77.127.12.178]) by a-mtaout23.012.net.il (HyperSendmail v2007.08) with ESMTPA id <0LZW00EDA4MZD020@a-mtaout23.012.net.il>; Fri, 24 Feb 2012 11:21:00 +0200 (IST) In-reply-to: <87vcmwwvk7.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:57161 Archived-At: > From: Thierry Volpiatto > Date: Fri, 24 Feb 2012 08:16:08 +0100 > > Just realize that this match was quite old. > I have merged this patch with last revision of today. > So ignore precedent and review this one. > I it's ok I will apply it on trunk. Some feedback below. Apologies if I say something silly because I didn't track this discussion from the beginning. > + (when (file-subdir-of-p to from) > + (error "Can't copy directory `%s' on itself" from)) A better error message would be (error "Cannot copy `%s' into its subdirectory `%s'" from to) IOW, don't assume that the fact of TO being a subdirectory of FROM is immediately evident to the user, just by looking at one of them. > + ;; In this case the 'name-constructor' have set the destination > + ;; 'to' to "~/test/foo" because the old > + ;; emacs23 behavior of `copy-directory' > + ;; was no not create the subdir and copy instead the contents only. ^^^^^^^^^^^^^ Something's wrong here. Did you mean "to not create"? If so, "not to create the subdirectory and instead copy the contents" is clearer. > + ;; With it's new behavior ^^^^ "its". "It's" is a short for "it is", which is not what you want here. > (similar to cp shell command) we don't ^^^^^^^^^^^^^^^^^^^ "to the `cp' shell command" > + ;; need such a construction, so modify the destination 'to' to ^^^^^^^^^^^^^^^^^^^^^^^^ What "construction"? This word doesn't belong here. > + ;; "~/test/" instead of "~/test/foo/". > + ;; If from and to are the same directory do the same, Suggest to use FROM and TO, in caps, to distinguish arguments from the rest of the comment text. > + (error "Can't copy directory `%s' on itself" from))) See above for a better error message text. > +(defun files-equal-p (file1 file2) > + "Return non-nil if FILE1 and FILE2 name the same file." > + (and (equal (file-remote-p file1) (file-remote-p file2)) > + (equal (file-attributes (file-truename (expand-file-name file1))) > + (file-attributes (file-truename (expand-file-name file2)))))) I don't understand why you use expand-file-name here: file-truename does it for you anyway. > +(defun file-subdir-of-p (file1 file2) > + "Check if FILE1 is a subdirectory of FILE2 on current filesystem. > +If directory FILE1 is the same than directory FILE2, return non--nil." Suggest to modify the doc string as follows: "Return non-nil if FILE1 is a subdirectory of FILE2. Note that a directory is treated by this function as a subdirectory of itself." Btw, I would call the arguments DIR1 and DIR2, otherwise the above sounds awkward ("FILE1 is a subdirectory ...") and even begs a question about what happens if FILE1 is not a directory, but a file living inside the directory FILE2. > + (when (and (not (or (file-remote-p file1) > + (file-remote-p file2))) > + (not (string= file1 "/")) Unixism alert! What about the equivalent "X:/" on Windows? Also, what should the following return? (file-subdir-of-p "/" "/") According to the doc string, it should return non-nil, but the above string= condition would seem to cause it return nil, right? > + (or (string= file2 "/") Same here, on both accounts. Why do you single-case "/", anyway? It's as good a directory as any. > + (loop with f1 = (expand-file-name (file-truename file1)) > + with f2 = (expand-file-name (file-truename file2)) file-truename already expands its argument, so why would you need to run it through expand-file-name again? > + for p = (string-match "^/" f1) Unixism alert again! > + (equal (file-attributes (file-truename root)) > + (file-attributes f2)))))) Why don't you use files-equal-p here? > + (when (file-subdir-of-p newname directory) > + (error "Can't copy directory `%s' on itself" directory)) See above. Finally, it looks like this function only works when its two arguments already exist; when they don't, it returns nil. If this is the intent, it should be reflected in the doc string. Thanks.