all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
* bug#25075: 26.0.50; [PATCH] Dired can now dereference symlinks when copying
@ 2016-11-30 18:04 Kaushal Modi
  2016-11-30 18:38 ` Eli Zaretskii
  2016-12-01  0:38 ` Glenn Morris
  0 siblings, 2 replies; 9+ messages in thread
From: Kaushal Modi @ 2016-11-30 18:04 UTC (permalink / raw)
  To: 25075

[-- 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 --]

^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2020-08-11 13:17 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-11-30 18:04 bug#25075: 26.0.50; [PATCH] Dired can now dereference symlinks when copying Kaushal Modi
2016-11-30 18:38 ` 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

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.