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: Mon, 27 Feb 2012 07:45:49 +0100 Message-ID: <87fwdwhizm.fsf@gmail.com> References: <87mx9su32g.fsf@web.de> <87pqd6wnvv.fsf@gmail.com> <87d395y1w0.fsf@gmail.com> <87zkc8x04p.fsf@gmail.com> <87vcmwwvk7.fsf@gmail.com> <834nugtwqf.fsf@gnu.org> <87r4xkwhky.fsf@gmail.com> <83vcmws3bs.fsf@gnu.org> <87ehtkwaiz.fsf@gmail.com> <87wr7cgsm3.fsf@gmx.de> <8762eww77b.fsf@gmail.com> <83pqd4roav.fsf@gnu.org> <87haygx97t.fsf@gmx.de> <87aa47rj6z.fsf@gmail.com> <878vjrxpej.fsf@gmx.de> <87pqd3i8ky.fsf@gmail.com> <87ipiuvsbw.fsf@gmx.de> <87k439gyu5.fsf@gmail.com> NNTP-Posting-Host: plane.gmane.org Mime-Version: 1.0 Content-Type: text/plain X-Trace: dough.gmane.org 1330325181 29403 80.91.229.3 (27 Feb 2012 06:46:21 GMT) X-Complaints-To: usenet@dough.gmane.org NNTP-Posting-Date: Mon, 27 Feb 2012 06:46:21 +0000 (UTC) Cc: 10489@debbugs.gnu.org, Michael Albinus To: Stefan Monnier Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Mon Feb 27 07:46:20 2012 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1S1uLj-0001aT-6k for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Feb 2012 07:46:19 +0100 Original-Received: from localhost ([::1]:35444 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1uLi-0000ft-LC for geb-bug-gnu-emacs@m.gmane.org; Mon, 27 Feb 2012 01:46:18 -0500 Original-Received: from eggs.gnu.org ([208.118.235.92]:57063) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1uLf-0000fL-7T for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2012 01:46:16 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1S1uLd-00028U-J6 for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2012 01:46:15 -0500 Original-Received: from debbugs.gnu.org ([140.186.70.43]:56871) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1S1uLd-00028G-Cf for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2012 01:46:13 -0500 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.72) (envelope-from ) id 1S1uOM-0001XF-1L for bug-gnu-emacs@gnu.org; Mon, 27 Feb 2012 01:49: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: Mon, 27 Feb 2012 06:49: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.13303253285877 (code B ref 10489); Mon, 27 Feb 2012 06:49:01 +0000 Original-Received: (at 10489) by debbugs.gnu.org; 27 Feb 2012 06:48:48 +0000 Original-Received: from localhost ([127.0.0.1]:58768 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S1uO7-0001Wj-CO for submit@debbugs.gnu.org; Mon, 27 Feb 2012 01:48:47 -0500 Original-Received: from mail-wi0-f172.google.com ([209.85.212.172]:57572) by debbugs.gnu.org with esmtp (Exim 4.72) (envelope-from ) id 1S1uO4-0001Wb-Dg for 10489@debbugs.gnu.org; Mon, 27 Feb 2012 01:48:45 -0500 Original-Received: by wicr5 with SMTP id r5so491330wic.3 for <10489@debbugs.gnu.org>; Sun, 26 Feb 2012 22:45:54 -0800 (PST) Received-SPF: pass (google.com: domain of thierry.volpiatto@gmail.com designates 10.180.77.228 as permitted sender) client-ip=10.180.77.228; Authentication-Results: mr.google.com; spf=pass (google.com: domain of thierry.volpiatto@gmail.com designates 10.180.77.228 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.77.228]) by 10.180.77.228 with SMTP id v4mr25096601wiw.2.1330325154051 (num_hops = 1); Sun, 26 Feb 2012 22:45:54 -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=Yli0j/kC6+brjzUakeWj/RWjBsfqxM92eETxEGYJDRg=; b=EY8JGTS4Wo5nUvLD7BVva3KG9joJZUL/o7saV9Tp5wWiNpUxGK/rza8xNycIHaFXFT oApNDKhOffvJjIOEPj4YDHnQrSSgj65oXbUGhdRKUK7w1uLuPNtBP0Y6oGIOc8n9PZMC l51Py/3+NTOI14jz5VcmhY3NLsw7LiczaLXsk= Original-Received: by 10.180.77.228 with SMTP id v4mr19924196wiw.2.1330325153975; Sun, 26 Feb 2012 22:45:53 -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 er8sm50773546wib.1.2012.02.26.22.45.51 (version=TLSv1/SSLv3 cipher=OTHER); Sun, 26 Feb 2012 22:45:52 -0800 (PST) In-Reply-To: (Stefan Monnier's message of "Sun, 26 Feb 2012 16:40:37 -0500") 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:57270 Archived-At: Stefan Monnier writes: >>> if both FILE1 and FILE2 do not exist. Either it is a bug, or it must >>> be documented. > > Since file-equal-p checks equality of *files* as opposed to equality of > file *names*, all we need to do is to remind (in the docstring) that > this predicate is only defined on existing files. I have modified files-equal-p and file-subdir-of-p to work with non--existing files, this allow to remove one call to file-subdir-of-p in copy-directory and not create the initial top directory in this case (not in this patch yet). --8<---------------cut here---------------start------------->8--- diff --git a/lisp/files.el b/lisp/files.el --- a/lisp/files.el +++ b/lisp/files.el @@ -4986,25 +4986,33 @@ (delete-directory-internal directory))))) (defun files-equal-p (file1 file2) - "Return non-nil if FILE1 and FILE2 name the same file." + "Return non-nil if FILE1 and FILE2 name the same file. +This function works even on non--existing files." (let ((handler (or (find-file-name-handler file1 'files-equal-p) (find-file-name-handler file2 'files-equal-p)))) (if handler (funcall handler 'files-equal-p file1 file2) - (equal (file-attributes (file-truename file1)) - (file-attributes (file-truename file2)))))) - -(defun file-subdir-of-p (dir1 dir2) + (let ((f1-attr (file-attributes (file-truename file1))) + (f2-attr (file-attributes (file-truename file2)))) + (if (and f1-attr f2-attr) + (equal f1-attr f2-attr) + (string= (file-truename + (file-name-as-directory file1)) + (file-truename + (file-name-as-directory file2)))))))) + +(defun file-subdir-of-p (dir1 dir2 &optional noexist) "Return non-nil if DIR1 is a subdirectory of DIR2. Note that a directory is treated by this function as a subdirectory of itself. -This function only works when its two arguments already exist, -when they don't, it returns nil." +This function only works when its two arguments already exist unless +optional argument NOEXIST is non--nil, otherwise it returns nil." (let ((handler (or (find-file-name-handler dir1 'file-subdir-of-p) (find-file-name-handler dir2 'file-subdir-of-p)))) (if handler - (funcall handler 'file-subdir-of-p dir1 dir2) - (when (and (file-directory-p dir1) - (file-directory-p dir2)) + (funcall handler 'file-subdir-of-p dir1 dir2 noexist) + (when (or noexist + (and (file-directory-p dir1) + (file-directory-p dir2))) (loop with f1 = (file-truename dir1) with f2 = (file-truename dir2) with ls1 = (or (split-string f1 "/" t) (list "/")) --8<---------------cut here---------------end--------------->8--- I will apply it today if no objections. -- Thierry Get my Gnupg key: gpg --keyserver pgp.mit.edu --recv-keys 59F29997