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 22:08:30 -0300 Message-ID: <87tujksz1t.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="28146"; 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 03:37: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 1mGtT7-00077K-GS for geb-bug-gnu-emacs@m.gmane-mx.org; Fri, 20 Aug 2021 03:37:14 +0200 Original-Received: from localhost ([::1]:53058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mGtT5-0003xD-0o for geb-bug-gnu-emacs@m.gmane-mx.org; Thu, 19 Aug 2021 21:37:11 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:54342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGtSw-0003wR-68 for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 21:37:02 -0400 Original-Received: from debbugs.gnu.org ([209.51.188.43]:49465) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mGtSv-0004QE-VI for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 21:37:01 -0400 Original-Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mGtSv-00047q-LR for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 21:37: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: Fri, 20 Aug 2021 01:37: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.162942337715800 (code B ref -1); Fri, 20 Aug 2021 01:37:01 +0000 Original-Received: (at submit) by debbugs.gnu.org; 20 Aug 2021 01:36:17 +0000 Original-Received: from localhost ([127.0.0.1]:32778 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGtS7-00046h-D4 for submit@debbugs.gnu.org; Thu, 19 Aug 2021 21:36:17 -0400 Original-Received: from lists.gnu.org ([209.51.188.17]:48618) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mGt1h-0003TC-Iz for submit@debbugs.gnu.org; Thu, 19 Aug 2021 21:08:54 -0400 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:50394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGt1h-0005v6-EY for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 21:08:53 -0400 Original-Received: from smtp.fing.edu.uy ([164.73.32.16]:53032) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mGt1d-0001xG-5A for bug-gnu-emacs@gnu.org; Thu, 19 Aug 2021 21:08:51 -0400 Original-Received: from localhost (localhost.localdomain [127.0.0.1]) by smtp.fing.edu.uy (Postfix) with ESMTP id 495BADF819 for ; Thu, 19 Aug 2021 22:08:44 -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 eVM9l-X69G4o for ; Thu, 19 Aug 2021 22:08:39 -0300 (-03) Original-Received: from localhost.localdomain (r167-60-28-245.dialup.adsl.anteldata.net.uy [167.60.28.245]) (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 0890CE0DA4 for ; Thu, 19 Aug 2021 22:08:38 -0300 (-03) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=fing.edu.uy; s=default; t=1629421719; bh=+Y/zfsNMdcbQ/A5x9JCf3YFXNbO8Ma5xbHHPIHVqrko=; h=From:To:Subject:Date; b=NlOMdkDxgxfsXoRcauBsaEwYVvxHbkDrqeh1+TqTXuFlDtucxE4l3EO9PHijcYm2k JfqGPHkM+TZusN76sqnI9xqPj/F9foIo6hOd8qilOuOBq+8V2R28vSb6ZIJoEAcpsf uXHWRFNzk+3EMGgVufqpYm9NMlwBU0Aq8k/WV3+g= 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 21:36:10 -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:212246 Archived-At: --=-=-= Content-Type: text/plain I failed to document the new behaviour in the docstring. The patch I sent didn't manage the creation of the new symlink correctly either, as it created it with the same name as the target. That is, in the examples given the result was: ------------------------- (copy-directory "~/tmp/foo" "~/Test" nil t) => [mcenturion@localhost ~]$ ls -l Test total 4 lrwxrwxrwx. 1 mcenturion mcenturion 26 ago 19 21:21 Test1 -> /home/mcenturion/tmp/Test1 ------------------------- This new patch corrects both mistakes. Sorry for the misfire. --=-=-= Content-Type: text/x-patch Content-Disposition: inline; filename=bug#10897.patch diff --git a/lisp/files.el b/lisp/files.el index 875ac55316..0bf8a2ea8d 100644 --- a/lisp/files.el +++ b/lisp/files.el @@ -6165,6 +6165,9 @@ copy-directory parent directories if they don't exist. Interactively, this happens by default. +If DIRECTORY is a symlink, create a symlink with the same target +as DIRECTORY. + If NEWNAME is a directory name, copy DIRECTORY as a subdirectory there. However, if called from Lisp with a non-nil optional argument COPY-CONTENTS, copy the contents of DIRECTORY directly @@ -6193,42 +6196,52 @@ 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 symlink with the same target. + (if (file-symlink-p directory) + (let ((target (car (file-attributes directory)))) + (if (directory-name-p newname) + (make-symbolic-link target + (concat newname + (file-name-nondirectory directory)) + t) + (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 --=-=-=--