Function: tramp-check-cached-permissions

tramp-check-cached-permissions is a byte-compiled function defined in tramp.el.gz.

Signature

(tramp-check-cached-permissions VEC ACCESS)

Documentation

Check file-attributes caches for VEC.

Return t if according to the cache access type ACCESS is known to be granted.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defun tramp-check-cached-permissions (vec access)
  "Check `file-attributes' caches for VEC.
Return t if according to the cache access type ACCESS is known to
be granted."
  (let ((result nil)
        (offset (cond
                 ((eq ?r access) 1)
                 ((eq ?w access) 2)
                 ((eq ?x access) 3)
                 ((eq ?s access) 3))))
    (dolist (suffix '("string" "integer") result)
      (setq
       result
       (or
        result
        (let ((file-attr
	       (or
		(tramp-get-file-property
		 vec (tramp-file-name-localname vec)
		 (concat "file-attributes-" suffix) nil)
		(file-attributes
		 (tramp-make-tramp-file-name vec) (intern suffix))))
              (remote-uid (tramp-get-remote-uid vec (intern suffix)))
              (remote-gid (tramp-get-remote-gid vec (intern suffix)))
	      (unknown-id
	       (if (string-equal suffix "string")
		   tramp-unknown-id-string tramp-unknown-id-integer)))
          (and
           file-attr
           (or
            ;; Not a symlink.
            (eq t (tramp-compat-file-attribute-type file-attr))
            (null (tramp-compat-file-attribute-type file-attr)))
           (or
            ;; World accessible.
            (eq access
		(aref (tramp-compat-file-attribute-modes file-attr)
		      (+ offset 6)))
            ;; User accessible and owned by user.
            (and
             (eq access
		 (aref (tramp-compat-file-attribute-modes file-attr) offset))
	     (or (equal remote-uid unknown-id)
		 (equal remote-uid
			(tramp-compat-file-attribute-user-id file-attr))
		 (equal unknown-id
			(tramp-compat-file-attribute-user-id file-attr))))
            ;; Group accessible and owned by user's principal group.
            (and
             (eq access
		 (aref (tramp-compat-file-attribute-modes file-attr)
		       (+ offset 3)))
             (or (equal remote-gid unknown-id)
		 (equal remote-gid
			(tramp-compat-file-attribute-group-id file-attr))
		 (equal unknown-id
			(tramp-compat-file-attribute-group-id
			 file-attr))))))))))))