Function: file-ownership-preserved-p
file-ownership-preserved-p is a byte-compiled function defined in
files.el.gz.
Signature
(file-ownership-preserved-p FILE &optional GROUP)
Documentation
Return t if deleting FILE and rewriting it would preserve the owner.
Return also t if FILE does not exist. If GROUP is non-nil, check whether the group would be preserved too.
Probably introduced at or before Emacs version 19.29.
Source Code
;; Defined in /usr/src/emacs/lisp/files.el.gz
(defun file-ownership-preserved-p (file &optional group)
"Return t if deleting FILE and rewriting it would preserve the owner.
Return also t if FILE does not exist. If GROUP is non-nil, check whether
the group would be preserved too."
(let ((handler (find-file-name-handler file 'file-ownership-preserved-p)))
(if handler
(funcall handler 'file-ownership-preserved-p file group)
(let ((attributes (file-attributes file 'integer)))
;; Return t if the file doesn't exist, since it's true that no
;; information would be lost by an (attempted) delete and create.
(or (null attributes)
(and (or (= (file-attribute-user-id attributes) (user-uid))
;; Files created on Windows by Administrator (RID=500)
;; have the Administrators group (RID=544) recorded as
;; their owner. Rewriting them will still preserve the
;; owner.
(and (eq system-type 'windows-nt)
(= (user-uid) 500)
(= (file-attribute-user-id attributes) 544)))
(or (not group)
;; On BSD-derived systems files always inherit the parent
;; directory's group, so skip the group-gid test.
(memq system-type '(berkeley-unix darwin gnu/kfreebsd))
(= (file-attribute-group-id attributes) (group-gid)))
(let* ((parent (or (file-name-directory file) "."))
(parent-attributes (file-attributes parent 'integer)))
(and parent-attributes
;; On some systems, a file created in a setuid directory
;; inherits that directory's owner.
(or
(= (file-attribute-user-id parent-attributes)
(user-uid))
(string-match
"^...[^sS]"
(file-attribute-modes parent-attributes)))
;; On many systems, a file created in a setgid directory
;; inherits that directory's group. On some systems
;; this happens even if the setgid bit is not set.
(or (not group)
(= (file-attribute-group-id parent-attributes)
(file-attribute-group-id attributes)))))))))))