Function: tramp-set-file-uid-gid
tramp-set-file-uid-gid is a byte-compiled function defined in
tramp.el.gz.
Signature
(tramp-set-file-uid-gid FILENAME &optional UID GID)
Documentation
Set the ownership for FILENAME.
If UID and GID are provided, these values are used; otherwise uid and gid of the corresponding remote or local user is taken, depending whether FILENAME is remote or local. Both parameters must be non-negative integers. The setgid bit of the upper directory is respected. If FILENAME is remote, a file name handler is called.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(and x "x") "-")))) ; !suid
;; This is a Tramp internal function. A general `set-file-uid-gid'
;; outside Tramp is not needed, I believe.
(defun tramp-set-file-uid-gid (filename &optional uid gid)
"Set the ownership for FILENAME.
If UID and GID are provided, these values are used; otherwise uid
and gid of the corresponding remote or local user is taken,
depending whether FILENAME is remote or local. Both parameters
must be non-negative integers.
The setgid bit of the upper directory is respected.
If FILENAME is remote, a file name handler is called."
(let* ((dir (file-name-directory filename))
(modes (file-modes dir)))
(when (and modes (not (zerop (logand modes #o2000))))
(setq gid (file-attribute-group-id (file-attributes dir)))))
(if (tramp-tramp-file-p filename)
(funcall (if (tramp-crypt-file-name-p filename)
#'tramp-crypt-file-name-handler #'tramp-file-name-handler)
#'tramp-set-file-uid-gid filename uid gid)
;; On W32 systems, "chown" does not work.
(unless (memq system-type '(ms-dos windows-nt))
(let ((uid (or (and (natnump uid) uid) (tramp-get-local-uid 'integer)))
(gid (or (and (natnump gid) gid) (tramp-get-local-gid 'integer))))
(tramp-call-process
nil "chown" nil nil nil (format "%d:%d" uid gid)
(tramp-unquote-shell-quote-argument filename))))))