Function: tramp-sh-handle-set-file-uid-gid

tramp-sh-handle-set-file-uid-gid is a byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-sh-handle-set-file-uid-gid FILENAME &optional UID GID)

Documentation

Like tramp-set-file-uid-gid for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-sh-handle-set-file-uid-gid (filename &optional uid gid)
  "Like `tramp-set-file-uid-gid' for Tramp files."
  ;; Modern Unices allow chown only for root.  So we might need
  ;; another implementation, see `dired-do-chown'.  OTOH, it is mostly
  ;; working with su(do)? when it is needed, so it shall succeed in
  ;; the majority of cases.
  (tramp-skeleton-set-file-modes-times-uid-gid filename
    ;; Don't modify `last-coding-system-used' by accident.
    (let ((last-coding-system-used last-coding-system-used))
      (if (and (zerop (user-uid)) (tramp-local-host-p v))
	  ;; If we are root on the local host, we can do it directly.
	  (tramp-set-file-uid-gid localname uid gid)
	(let ((uid (or (and (natnump uid) uid)
		       (tramp-get-remote-uid v 'integer)))
	      (gid (or (and (natnump gid) gid)
		       (tramp-get-remote-gid v 'integer))))
	  (tramp-send-command
	   v (format
	      "chown %d:%d %s" uid gid
	      (tramp-shell-quote-argument localname))))))))