From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Marco Centurion Newsgroups: gmane.emacs.bugs Subject: bug#10897: copy-directory create new directory when copying a symlink Date: Thu, 19 Aug 2021 18:47:33 -0300 Message-ID: <87y28xrtsa.fsf@fing.edu.uy> References: <874nuchddl.fsf@gmail.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=-=-=" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="40852"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/28.0.50 (gnu/linux) To: 10897@debbugs.gnu.org Original-X-From: bug-gnu-emacs-bounces+geb-bug-gnu-emacs=m.gmane-mx.org@gnu.org Fri Aug 20 00:17:14 2021 Return-path: Envelope-to: geb-bug-gnu-emacs@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1mGqLZ-000AL1-EN for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Aug 2021 00:17:14 +0200 Original-Received: from localhost ([::1]:36946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGqLX-0007P1-IX for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Aug 2021 18:17:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:52564) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGqLO-0007Nr-4W for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 18:17:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49367) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGqLN-0000bU-Ty for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 18:17:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mGqLN-0007tj-No for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 18:17:01 -0400 X-Loop: help-debbugs@gnu.org In-Reply-To: <874nuchddl.fsf@gmail.com> Resent-From: Marco Centurion Original-Sender: "Debbugs-submit" Resent-CC: bug-gnu-emacs@gnu.org Resent-Date: Thu, 19 Aug 2021 22:17:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 10897 X-GNU-PR-Package: emacs X-GNU-PR-Keywords: confirmed X-Debbugs-Original-To: bug-gnu-emacs@gnu.org Original-Received: via spool by submit@debbugs.gnu.org id=B.162941140930337 (code B ref -1); Thu, 19 Aug 2021 22:17:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 19 Aug 2021 22:16:49 +0000 Original-Received: from localhost ([127.0.0.1]:60913 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGqL9-0007tB-Mz for submit@debbugs.gnu.org; Thu, 19 Aug 2021 18:16:49 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:58190) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGpt9-0007CV-Bi for submit@debbugs.gnu.org; Thu, 19 Aug 2021 17:47:52 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:46014) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGpt9-0007Yw-3z for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 17:47:51 -0400 Original-Received: from smtp.fing.edu.uy ([164.73.32.16]:57962) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGpt3-0005h2-Bf for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 17:47:49 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.fing.edu.uy (Postfix) with ESMTP id AF15FE0E15 for ; Thu, 19 Aug 2021 18:47:38 -0300 (-03) X-Virus-Scanned: amavisd-new at fing.edu.uy Original-Received: from smtp.fing.edu.uy ([127.0.0.1]) by localhost (smtp.fing.edu.uy [127.0.0.1]) (amavisd-new, port 10024) with LMTP id k_VijP6wPriZ for ; Thu, 19 Aug 2021 18:47:33 -0300 (-03) Original-Received: from localhost.localdomain (r186-48-97-167.dialup.adsl.anteldata.net.uy [186.48.97.167]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: mcenturion) by smtp.fing.edu.uy (Postfix) with ESMTPSA id 8E744E0E19 for ; Thu, 19 Aug 2021 18:47:33 -0300 (-03) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fing.edu.uy; s=default; t=1629409653; bh=J97fkVyvKQxSFkKzlvSNpIB4CUcc4ynrV08iIQQyY/0=; h=From:To:Subject:Date; b=DAXbM5uwj8UYc6/PSrLWDOqBF5coTSbQ2tDqA6qpuHMEPBh71dt7gNcD7xkAysURe P0CcJfnd9VvblpCXgXNHHYWzkLjYTciKC8COcnGdtI+pHNk5+7kCAuIT7V2S6B1O5M JED0YPlIi/L1nUrJTsvOBnpfmwS2GRbF3tQIhB54= Received-SPF: pass client-ip=164.73.32.16; envelope-from=mcenturion@fing.edu.uy; helo=smtp.fing.edu.uy X-Spam_score_int: -5 X-Spam_score: -0.6 X-Spam_bar: / X-Spam_report: (-0.6 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FAKE_REPLY_C=1.486, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Thu, 19 Aug 2021 18:16:46 -0400 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list 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-mx.org@gnu.org Original-Sender: "bug-gnu-emacs" Xref: news.gmane.io gmane.emacs.bugs:212241 Archived-At: --=-=-= Content-Type: text/plain This patch seems to fix this issue. Turns out that the code didn't take into consideration the case when the directory we want to copy is itself a symlink. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=bug#10897.patch diff --git a/lisp/files.el b/lisp/files.el index 875ac55316..424cf1bea0 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6193,42 +6193,48 @@ copy-directory (setq directory (directory-file-name (expand-file-name directory)) newname (expand-file-name newname)) - (cond ((not (directory-name-p newname)) - ;; If NEWNAME is not a directory name, create it; - ;; that is where we will copy the files of DIRECTORY. - (make-directory newname parents)) - ;; 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)) - (t (setq follow t))) - - ;; Copy recursively. - (dolist (file - ;; We do not want to copy "." and "..". - (directory-files directory 'full - directory-files-no-dot-files-regexp)) - (let ((target (concat (file-name-as-directory newname) - (file-name-nondirectory file))) - (filetype (car (file-attributes file)))) - (cond - ((eq filetype t) ; Directory but not a symlink. - (copy-directory file target keep-time parents t)) - ((stringp filetype) ; Symbolic link - (make-symbolic-link filetype target t)) - ((copy-file file target t keep-time))))) - - ;; Set directory attributes. - (let ((modes (file-modes directory)) - (times (and keep-time (file-attribute-modification-time - (file-attributes directory)))) - (follow-flag (unless follow 'nofollow))) - (if modes (set-file-modes newname modes follow-flag)) - (if times (set-file-times newname times follow-flag)))))) + ;; If DIRECTORY is a symlink, create a NEWNAME symlink + ;; with the same target. + (if (file-symlink-p directory) + (let ((target (car (file-attributes directory)))) + (make-symbolic-link target newname t)) + ;; Else proceed to copy as a regular directory + (cond ((not (directory-name-p newname)) + ;; If NEWNAME is not a directory name, create it; + ;; that is where we will copy the files of DIRECTORY. + (make-directory newname parents)) + ;; 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)) + (t (setq follow t))) + + ;; Copy recursively. + (dolist (file + ;; We do not want to copy "." and "..". + (directory-files directory 'full + directory-files-no-dot-files-regexp)) + (let ((target (concat (file-name-as-directory newname) + (file-name-nondirectory file))) + (filetype (car (file-attributes file)))) + (cond + ((eq filetype t) ; Directory but not a symlink. + (copy-directory file target keep-time parents t)) + ((stringp filetype) ; Symbolic link + (make-symbolic-link filetype target t)) + ((copy-file file target t keep-time))))) + + ;; Set directory attributes. + (let ((modes (file-modes directory)) + (times (and keep-time (file-attribute-modification-time + (file-attributes directory)))) + (follow-flag (unless follow 'nofollow))) + (if modes (set-file-modes newname modes follow-flag)) + (if times (set-file-times newname times follow-flag))))))) ;; At time of writing, only info uses this. --=-=-= Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable --=20 Marco Centurion Unidad de Recursos Inform=C3=A1ticos Facultad de Ingenier=C3=ADa - UdelaR --=-=-=--