Function: tramp-sh-handle-add-name-to-file
tramp-sh-handle-add-name-to-file is a byte-compiled function defined
in tramp-sh.el.gz.
Signature
(tramp-sh-handle-add-name-to-file FILENAME NEWNAME &optional OK-IF-ALREADY-EXISTS)
Documentation
Like add-name-to-file for Tramp files.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;; cp, mv and ln
(defun tramp-sh-handle-add-name-to-file
(filename newname &optional ok-if-already-exists)
"Like `add-name-to-file' for Tramp files."
(unless (tramp-equal-remote filename newname)
(with-parsed-tramp-file-name
(if (tramp-tramp-file-p filename) filename newname) nil
(tramp-error
v 'file-error
"add-name-to-file: %s"
"only implemented for same method, same user, same host")))
(with-parsed-tramp-file-name (expand-file-name filename) v1
(with-parsed-tramp-file-name (expand-file-name newname) v2
(let ((ln (when v1 (tramp-get-remote-ln v1))))
;; Do the 'confirm if exists' thing.
(when (file-exists-p newname)
;; What to do?
(if (or (null ok-if-already-exists) ; not allowed to exist
(and (numberp ok-if-already-exists)
(not (yes-or-no-p
(format
"File %s already exists; make it a link anyway?"
v2-localname)))))
(tramp-error v2 'file-already-exists newname)
(delete-file newname)))
(tramp-flush-file-properties v2 v2-localname)
(tramp-barf-unless-okay
v1
(format "%s %s %s" ln
(tramp-shell-quote-argument v1-localname)
(tramp-shell-quote-argument v2-localname))
"error with add-name-to-file, see buffer `%s' for details"
(buffer-name))))))