all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Kaushal Modi <kaushal.modi@gmail.com>
To: 25075@debbugs.gnu.org
Subject: bug#25075: 26.0.50; [PATCH] Dired can now dereference symlinks when copying
Date: Wed, 30 Nov 2016 18:04:17 +0000	[thread overview]
Message-ID: <CAFyQvY2iedHj-cLxmwTmQCegPZNjqyS6MafGdorNRLrMFfhicA@mail.gmail.com> (raw)

[-- Attachment #1: Type: text/plain, Size: 2851 bytes --]

Hello,

Can you review and comment on the below patch. I came up with a necessity
to copy symlinks from one dired buffer to another dired buffer as a
dereferenced copy of that symlink.

In terminal, I would use the -L option of the cp command to do the same.

The current default behavior is unchanged as the new defcustom
dired-copy-dereference is set to nil.

From 4c4185b9d4df2dcbbb6e1e7fa8a21b75e84ca79f Mon Sep 17 00:00:00 2001
From: Kaushal Modi <kaushal.modi@gmail.com>
Date: Wed, 30 Nov 2016 12:52:42 -0500
Subject: [PATCH] Dired can now dereference symlinks when copying

* lisp/dired.el (dired-copy-dereference): New defcustom, defaults to
nil.

* lisp/dired-aux.el (dired-copy-file-recursive): Add new optional
argument `dereference'.

* lisp/dired-aux.el (dired-copy-file): Use `dired-copy-dereference' as
the `dereference' argument to `dired-copy-file-recursive'.
---
 lisp/dired-aux.el | 8 +++++---
 lisp/dired.el     | 6 ++++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/lisp/dired-aux.el b/lisp/dired-aux.el
index f94e053..149c540 100644
--- a/lisp/dired-aux.el
+++ b/lisp/dired-aux.el
@@ -1507,12 +1507,13 @@ dired-handle-overwrite
 (defun dired-copy-file (from to ok-flag)
   (dired-handle-overwrite to)
   (dired-copy-file-recursive from to ok-flag dired-copy-preserve-time t
-     dired-recursive-copies))
+     dired-recursive-copies dired-copy-dereference))

 (declare-function make-symbolic-link "fileio.c")

 (defun dired-copy-file-recursive (from to ok-flag &optional
-       preserve-time top recursive)
+       preserve-time top recursive
+                                       dereference)
   (when (and (eq t (car (file-attributes from)))
      (file-in-directory-p to from))
     (error "Cannot copy `%s' into its subdirectory `%s'" from to))
@@ -1524,7 +1525,8 @@ dired-copy-file-recursive
  (copy-directory from to preserve-time)
       (or top (dired-handle-overwrite to))
       (condition-case err
-  (if (stringp (car attrs))
+  (if (and (not dereference)
+                   (stringp (car attrs)))
       ;; It is a symlink
       (make-symbolic-link (car attrs) to ok-flag)
     (copy-file from to ok-flag preserve-time))
diff --git a/lisp/dired.el b/lisp/dired.el
index daa6d77..ca7ab28 100644
--- a/lisp/dired.el
+++ b/lisp/dired.el
@@ -191,6 +191,12 @@ dired-copy-preserve-time
   :type 'boolean
   :group 'dired)

+(defcustom dired-copy-dereference nil
+  "If non-nil, Dired dereferences symlinks when copying them.
+This is similar to the \"-L\" option for the \"cp\" shell command."
+  :type 'boolean
+  :group 'dired)
+                                        ;
 ; These variables were deleted and the replacements are on files.el.
 ; We leave aliases behind for back-compatibility.
 (defvaralias 'dired-free-space-program 'directory-free-space-program)
-- 
2.10.0

-- 

Kaushal Modi

[-- Attachment #2: Type: text/html, Size: 4725 bytes --]

             reply	other threads:[~2016-11-30 18:04 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-11-30 18:04 Kaushal Modi [this message]
2016-11-30 18:38 ` bug#25075: 26.0.50; [PATCH] Dired can now dereference symlinks when copying Eli Zaretskii
2016-11-30 18:42   ` Kaushal Modi
2016-12-01  0:38 ` Glenn Morris
2016-12-01  3:39   ` Eli Zaretskii
2016-12-01  4:12   ` Kaushal Modi
2016-12-01  6:06     ` Kaushal Modi
2020-08-11 13:17       ` Lars Ingebrigtsen
2019-06-24 23:17   ` Lars Ingebrigtsen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAFyQvY2iedHj-cLxmwTmQCegPZNjqyS6MafGdorNRLrMFfhicA@mail.gmail.com \
    --to=kaushal.modi@gmail.com \
    --cc=25075@debbugs.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.