From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!not-for-mail From: Thierry Volpiatto Newsgroups: gmane.emacs.bugs Subject: bug#10489: 24.0.92; dired-do-copy may create infinite directory hierarchy Date: Fri, 24 Feb 2012 10:49:15 +0100 Message-ID: <87mx884l44.fsf@gmail.com> References: <87mx9su32g.fsf@web.de> <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> <834nugtwqf.fsf@gnu.org> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330077054 24092 80.91.229.3 (24 Feb 2012 09:50:54 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Fri, 24 Feb 2012 09:50:54 +0000 (UTC) Cc: 10489@debbugs.gnu.org To: Eli Zaretskii Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Fri Feb 24 10:50: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 1S0rng-0001NR-8C for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Feb 2012 10:50:52 +0100 Original-Received: from localhost ([::1]:35935 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rna-000331-Tp for geb-bug-gnu-emacs@m.gmane.org; Fri, 24 Feb 2012 04:50:46 -0500 Original-Received: from eggs.gnu.org ([140.186.70.92]:51107) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rnS-00032p-Ou for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:50:44 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S0rnR-0005AO-Bk for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:50:38 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:49783) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S0rnR-000597-3S for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:50:37 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1S0rpm-0000sS-1N for bug-gnu-emacs@gnu.org; Fri, 24 Feb 2012 04:53:02 -0500 X-Loop: help-debbugs@gnu.org Resent-From: Thierry Volpiatto Original-Sender: debbugs-submit-bounces@debbugs.gnu.org Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Fri, 24 Feb 2012 09:53: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.13300771223297 (code B ref 10489); Fri, 24 Feb 2012 09:53:01 +0000 Original-Received: (at 10489) by debbugs.gnu.org; 24 Feb 2012 09:52:02 +0000 Original-Received: from localhost ([127.0.0.1]:53406 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S0roo-0000r8-5J for submit@debbugs.gnu.org; Fri, 24 Feb 2012 04:52:02 -0500 Original-Received: from mail-ww0-f42.google.com ([74.125.82.42]:62329) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S0rol-0000qb-V1 for 10489@debbugs.gnu.org; Fri, 24 Feb 2012 04:52:01 -0500 Original-Received: by wgbgn7 with SMTP id gn7so267729wgb.3 for <10489@debbugs.gnu.org>; Fri, 24 Feb 2012 01:49:21 -0800 (PST) Received-SPF: pass (google.com: domain of thierry.volpiatto@gmail.com designates 10.180.90.225 as permitted sender) client-ip=10.180.90.225; Authentication-Results: mr.google.com; spf=pass (google.com: domain of thierry.volpiatto@gmail.com designates 10.180.90.225 as permitted sender) smtp.mail=thierry.volpiatto@gmail.com; dkim=pass header.i=thierry.volpiatto@gmail.com Original-Received: from mr.google.com ([10.180.90.225]) by 10.180.90.225 with SMTP id bz1mr3469492wib.5.1330076961223 (num_hops = 1); Fri, 24 Feb 2012 01:49:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version:content-type; bh=ukhoAe1jxOmLzihGbDXwnj2ZJC9Sh3oY1aNxQiZuu3U=; b=xc7zZg94ld+Z45eT77yjI3FFCjrtBqYzlJrAYjdCMwMKqVkmjteb+9xZ8Iu305A6Mq G1BtVJg95sCzdUpriyqzHutSvccRg6mmTgipNz+ViHYZnuPBZoklV3cqSsfY2UBHshYq RrKTxM7T2lgB4SdPVQVU4L0NIfb/kObD/pQWA= Original-Received: by 10.180.90.225 with SMTP id bz1mr2776839wib.5.1330076961175; Fri, 24 Feb 2012 01:49:21 -0800 (PST) Original-Received: from thierry-MM061 (lbe83-2-78-243-104-167.fbx.proxad.net. [78.243.104.167]) by mx.google.com with ESMTPS id s2sm6148827wix.3.2012.02.24.01.49.18 (version=TLSv1/SSLv3 cipher=OTHER); Fri, 24 Feb 2012 01:49:20 -0800 (PST) In-Reply-To: <834nugtwqf.fsf@gnu.org> (Eli Zaretskii's message of "Fri, 24 Feb 2012 11:19:04 +0200") User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/24.0.93 (gnu/linux) 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:57162 Archived-At: Hi Eli and thanks for your feedback. Eli Zaretskii writes: > 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) Agree. > 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. Yes thanks, I always do this mistake. >> (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, Ok for all corrections in comments. > 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. Same agree on this. >> +(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. Yes, agree, vestiges of precedents changes. >> +(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." Ok > 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. Agree. >> + (when (and (not (or (file-remote-p file1) >> + (file-remote-p file2))) >> + (not (string= file1 "/")) > > Unixism alert! What about the equivalent "X:/" on Windows? Think this is no more needed. > 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? Right. >> + (or (string= file2 "/") > > Same here, on both accounts. Why do you single-case "/", anyway? > It's as good a directory as any. Should be removed yes. >> + (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? Yes same as above. >> + for p = (string-match "^/" f1) > > Unixism alert again! No, it is not, this allow the function to work both on window and nix. See (if p (concat "/" i) (concat i "/")) Will add comment there. >> + (equal (file-attributes (file-truename root)) >> + (file-attributes f2)))))) > > Why don't you use files-equal-p here? I think I can, don't remember though, I have to check. >> + (when (file-subdir-of-p newname directory) >> + (error "Can't copy directory `%s' on itself" directory)) > > See above. Same agree. > 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. It is not the intent, but that is a good question, what if I copy e.g: ~/tmp/Test to ~/tmp/Test/Test1 where Test1 is a non--existing subdir of Test. Will check this, thanks. Though that the change that would follow later after 24.1 should fix this, falling back with the same behavior as 'cp'. -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997