Function: tramp-convert-file-attributes

tramp-convert-file-attributes is an autoloaded and byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-convert-file-attributes VEC ATTR)

Documentation

Convert file-attributes ATTR generated by perl script, stat or ls.

Convert file mode bits to string and set virtual device number. Return ATTR.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;; FIXME: Move to tramp.el?
;;;###tramp-autoload
(defun tramp-convert-file-attributes (vec attr)
  "Convert `file-attributes' ATTR generated by perl script, stat or ls.
Convert file mode bits to string and set virtual device number.
Return ATTR."
  (when attr
    (save-match-data
      ;; Remove color escape sequences from symlink.
      (when (stringp (car attr))
	(while (string-match tramp-display-escape-sequence-regexp (car attr))
	  (setcar attr (replace-match "" nil nil (car attr)))))
      ;; Convert uid and gid.  Use `tramp-unknown-id-integer' as
      ;; indication of unusable value.
      (when (and (numberp (nth 2 attr)) (< (nth 2 attr) 0))
	(setcar (nthcdr 2 attr) tramp-unknown-id-integer))
      (when (and (floatp (nth 2 attr))
		 (<= (nth 2 attr) most-positive-fixnum))
	(setcar (nthcdr 2 attr) (round (nth 2 attr))))
      (when (and (numberp (nth 3 attr)) (< (nth 3 attr) 0))
	(setcar (nthcdr 3 attr) tramp-unknown-id-integer))
      (when (and (floatp (nth 3 attr))
		 (<= (nth 3 attr) most-positive-fixnum))
	(setcar (nthcdr 3 attr) (round (nth 3 attr))))
      ;; Convert last access time.
      (unless (listp (nth 4 attr))
	(setcar (nthcdr 4 attr) (seconds-to-time (nth 4 attr))))
      ;; Convert last modification time.
      (unless (listp (nth 5 attr))
	(setcar (nthcdr 5 attr) (seconds-to-time (nth 5 attr))))
      ;; Convert last status change time.
      (unless (listp (nth 6 attr))
	(setcar (nthcdr 6 attr) (seconds-to-time (nth 6 attr))))
      ;; Convert file size.
      (when (< (nth 7 attr) 0)
	(setcar (nthcdr 7 attr) -1))
      (when (and (floatp (nth 7 attr))
		 (<= (nth 7 attr) most-positive-fixnum))
	(setcar (nthcdr 7 attr) (round (nth 7 attr))))
      ;; Convert file mode bits to string.
      (unless (stringp (nth 8 attr))
	(setcar (nthcdr 8 attr) (tramp-file-mode-from-int (nth 8 attr)))
	(when (stringp (car attr))
          (aset (nth 8 attr) 0 ?l)))
      ;; Convert directory indication bit.
      (when (string-prefix-p "d" (nth 8 attr))
	(setcar attr t))
      ;; Convert symlink from `tramp-do-file-attributes-with-stat'.
      ;; Decode also multibyte string.
      (when (consp (car attr))
	(setcar attr
		(and (stringp (caar attr))
		     (string-match ".+ -> .\\(.+\\)." (caar attr))
		     (decode-coding-string
		      (match-string 1 (caar attr)) 'utf-8))))
      ;; Set file's gid change bit.
      (setcar (nthcdr 9 attr)
              (if (numberp (nth 3 attr))
                  (not (= (nth 3 attr)
                          (tramp-get-remote-gid vec 'integer)))
		(not (string-equal
                      (nth 3 attr)
                      (tramp-get-remote-gid vec 'string)))))
      ;; Convert inode.
      (when (floatp (nth 10 attr))
	(setcar (nthcdr 10 attr)
		(condition-case nil
                    (let ((high (nth 10 attr))
                          middle low)
                      (if (<= high most-positive-fixnum)
                          (floor high)
			;; The low 16 bits.
			(setq low (mod high #x10000)
                              high (/ high #x10000))
			(if (<= high most-positive-fixnum)
                            (cons (floor high) (floor low))
                          ;; The middle 24 bits.
                          (setq middle (mod high #x1000000)
				high (/ high #x1000000))
                          (cons (floor high)
				(cons (floor middle) (floor low))))))
                  ;; Inodes can be incredible huge.  We must hide this.
                  (error (tramp-get-inode vec)))))
      ;; Set virtual device number.
      (setcar (nthcdr 11 attr)
              (tramp-get-device vec)))
    attr))