From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Paul Eggert Newsgroups: gmane.emacs.bugs Subject: bug#28451: 26.0.50; copy-directory no longer creates parent directories of target if they do not exist Date: Sun, 17 Sep 2017 13:15:47 -0700 Organization: UCLA Computer Science Department Message-ID: References: <97E0F6C6-FDDF-432A-823C-578013696243@gmail.com> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="------------481FE66B7584CEC604FE8847" X-Trace: blaine.gmane.org 1505679437 10497 195.159.176.226 (17 Sep 2017 20:17:17 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Sun, 17 Sep 2017 20:17:17 +0000 (UTC) User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 Cc: emacs@a.ndrew.pw, 28451-done@debbugs.gnu.org To: Andrew Christianson Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane.org@gnu.org Sun Sep 17 22:17:08 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 1dtg04-0002NF-3z for geb-bug-gnu-emacs@m.gmane.org; Sun, 17 Sep 2017 22:17:08 +0200 Original-Received: from localhost ([::1]:33571 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtg0A-0007bv-Tx for geb-bug-gnu-emacs@m.gmane.org; Sun, 17 Sep 2017 16:17:14 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:57322) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dtg03-0007bZ-3Z for bug-gnu-emacs@gnu.org; Sun, 17 Sep 2017 16:17:09 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dtfzy-0005h3-DK for bug-gnu-emacs@gnu.org; Sun, 17 Sep 2017 16:17:07 -0400 Original-Received: from debbugs.gnu.org ([208.118.235.43]:36638) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dtfzy-0005g0-8W for bug-gnu-emacs@gnu.org; Sun, 17 Sep 2017 16:17:02 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1dtfzy-0000K2-2s for bug-gnu-emacs@gnu.org; Sun, 17 Sep 2017 16:17:02 -0400 Resent-From: Paul Eggert Original-Sender: "Debbugs-submit" Resent-To: bug-gnu-emacs@gnu.org Resent-Date: Sun, 17 Sep 2017 20:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: cc-closed 28451 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: Mail-Followup-To: 28451@debbugs.gnu.org, eggert@cs.ucla.edu, emacs@a.ndrew.pw Original-Received: via spool by 28451-done@debbugs.gnu.org id=D28451.15056793661167 (code D ref 28451); Sun, 17 Sep 2017 20:17:01 +0000 Original-Received: (at 28451-done) by debbugs.gnu.org; 17 Sep 2017 20:16:06 +0000 Original-Received: from localhost ([127.0.0.1]:45319 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dtfz2-0000Ij-JN for submit@debbugs.gnu.org; Sun, 17 Sep 2017 16:16:06 -0400 Original-Received: from zimbra.cs.ucla.edu ([131.179.128.68]:48226) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dtfyx-0000Hv-94 for 28451-done@debbugs.gnu.org; Sun, 17 Sep 2017 16:16:03 -0400 Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id A149A160BF0; Sun, 17 Sep 2017 13:15:52 -0700 (PDT) Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10032) with ESMTP id EyK7dWFM8aSD; Sun, 17 Sep 2017 13:15:48 -0700 (PDT) Original-Received: from localhost (localhost [127.0.0.1]) by zimbra.cs.ucla.edu (Postfix) with ESMTP id 46C86160D13; Sun, 17 Sep 2017 13:15:48 -0700 (PDT) X-Virus-Scanned: amavisd-new at zimbra.cs.ucla.edu Original-Received: from zimbra.cs.ucla.edu ([127.0.0.1]) by localhost (zimbra.cs.ucla.edu [127.0.0.1]) (amavisd-new, port 10026) with ESMTP id skPjJ2mgyqTp; Sun, 17 Sep 2017 13:15:48 -0700 (PDT) Original-Received: from [192.168.1.9] (unknown [47.154.18.85]) by zimbra.cs.ucla.edu (Postfix) with ESMTPSA id 248F71608AA; Sun, 17 Sep 2017 13:15:48 -0700 (PDT) In-Reply-To: <97E0F6C6-FDDF-432A-823C-578013696243@gmail.com> Content-Language: en-US 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:137036 Archived-At: This is a multi-part message in MIME format. --------------481FE66B7584CEC604FE8847 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: quoted-printable Andrew Christianson wrote: > - (make-directory newname t))) > + (make-directory newname t)) > + ((and copy-contents (not (file-directory-p newname))) > + (make-directory newname parents))) Thanks for clarifying the test case and for the proposed patch. I reprodu= ced the=20 bug on Fedora 26 and wrote a test case to test case for the bug. Although= the=20 abovementioned patch should work on Fedora, it won't work on platforms th= at do=20 not allow trailing / on mkdir arguments. So I installed the attached patc= h into=20 the emacs-26 branch, and am boldly marking this bug as fixed. Please give= it a try. --------------481FE66B7584CEC604FE8847 Content-Type: text/x-patch; name="0001-Fix-recently-introduced-copy-directory-bug.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="0001-Fix-recently-introduced-copy-directory-bug.patch" =46rom 37b5e661d298cbfe51422cd515b6696a1cdaa868 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Sun, 17 Sep 2017 12:56:00 -0700 Subject: [PATCH] Fix recently-introduced copy-directory bug Problem reported by Andrew Christianson (Bug#28451): * lisp/files.el (copy-directory): If COPY-CONTENTS, make the destination directory if it does not exist, even if it is a directory name. Simplify, and omit unnecessary test for an already-existing non-directory target, since make-directory diagnoses that for us now. * test/lisp/files-tests.el (files-tests--copy-directory): Test for this bug. --- lisp/files.el | 20 +++++++++----------- test/lisp/files-tests.el | 11 +++++++++++ 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/lisp/files.el b/lisp/files.el index c55c809..133fed9 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -5372,7 +5372,7 @@ make-directory (while (progn (setq parent (directory-file-name (file-name-directory dir))) - (condition-case err + (condition-case () (files--ensure-directory dir) (file-missing ;; Do not loop if root does not exist (Bug#2309). @@ -5544,16 +5544,14 @@ copy-directory ;; If NEWNAME is not a directory name, create it; ;; that is where we will copy the files of DIRECTORY. (make-directory newname parents)) - ;; If NEWNAME is a directory name and COPY-CONTENTS - ;; is nil, copy into NEWNAME/[DIRECTORY-BASENAME]. - ((not copy-contents) - (setq newname (concat newname - (file-name-nondirectory directory))) - (and (file-exists-p newname) - (not (file-directory-p newname)) - (error "Cannot overwrite non-directory %s with a directory" - newname)) - (make-directory newname t))) + ;; NEWNAME is a directory name. If COPY-CONTENTS is non-nil, + ;; create NEWNAME if it is not already a directory; + ;; otherwise, create NEWNAME/[DIRECTORY-BASENAME]. + ((if copy-contents + (or parents (not (file-directory-p newname))) + (setq newname (concat newname + (file-name-nondirectory directory)))) + (make-directory (directory-file-name newname) parents))) =20 ;; Copy recursively. (dolist (file diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el index ef216c3..3117ea6 100644 --- a/test/lisp/files-tests.el +++ b/test/lisp/files-tests.el @@ -393,5 +393,16 @@ files-tests--with-temp-file (should (null (save-buffer))) (should (eq (buffer-size) 1)))))) =20 +(ert-deftest files-tests--copy-directory () + (let* ((dir (make-temp-file "files-mkdir-test" t)) + (dirname (file-name-as-directory dir)) + (source (concat dirname "source")) + (dest (concat dirname "dest/new/directory/")) + (file (concat (file-name-as-directory source) "file"))) + (make-directory source) + (write-region "" nil file) + (copy-directory source dest t t t) + (should (file-exists-p (concat dest "file"))))) + (provide 'files-tests) ;;; files-tests.el ends here --=20 2.7.4 --------------481FE66B7584CEC604FE8847--