Function: tramp-skeleton-make-symbolic-link

tramp-skeleton-make-symbolic-link is a macro defined in tramp.el.gz.

Signature

(tramp-skeleton-make-symbolic-link TARGET LINKNAME &optional OK-IF-ALREADY-EXISTS &rest BODY)

Documentation

Skeleton for tramp-*-handle-make-symbolic-link.

BODY is the backend specific code. If TARGET is a non-Tramp file, it is used verbatim as the target of the symlink. If TARGET is a Tramp file, only the localname component is used as the target of the symlink if it is located on the same host. Otherwise, TARGET is quoted.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defmacro tramp-skeleton-make-symbolic-link
  (target linkname &optional ok-if-already-exists &rest body)
  "Skeleton for `tramp-*-handle-make-symbolic-link'.
BODY is the backend specific code.
If TARGET is a non-Tramp file, it is used verbatim as the target
of the symlink.  If TARGET is a Tramp file, only the localname
component is used as the target of the symlink if it is located
on the same host.  Otherwise, TARGET is quoted."
  (declare (indent 3) (debug t))
  `(with-parsed-tramp-file-name  (expand-file-name ,linkname) nil
     ;; If TARGET is a Tramp name, use just the localname component.
     ;; Don't check for a proper method.
     (let ((non-essential t))
       (when (and (tramp-tramp-file-p ,target)
		  (tramp-file-name-equal-p v (tramp-dissect-file-name ,target)))
	 (setf ,target (tramp-file-local-name (expand-file-name ,target))))
       ;; There could be a cyclic link.
       (tramp-flush-file-properties
	v (tramp-drop-volume-letter
	   (expand-file-name
	    ,target (tramp-file-local-name default-directory)))))

     ;; If TARGET is still remote, quote it.
     (if (tramp-tramp-file-p ,target)
	 (make-symbolic-link
	  (file-name-quote ,target 'top) ,linkname ,ok-if-already-exists)

       ;; Do the 'confirm if exists' thing.
       (when (file-exists-p ,linkname)
	 ;; 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?"
			     localname)))))
	     (tramp-error v 'file-already-exists localname)
	   (delete-file ,linkname)))

       ;; We must also flush the cache of the directory, because
       ;; `file-attributes' reads the values from there.
       (tramp-flush-file-properties v localname)

       ,@body)))