Function: tramp-do-file-attributes-with-ls
tramp-do-file-attributes-with-ls is a byte-compiled function defined
in tramp-sh.el.gz.
Signature
(tramp-do-file-attributes-with-ls VEC LOCALNAME)
Documentation
Implement file-attributes for Tramp files using the ls(1) command.
Source Code
;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
(defun tramp-do-file-attributes-with-ls (vec localname)
"Implement `file-attributes' for Tramp files using the ls(1) command."
(tramp-message vec 5 "file attributes with ls: %s" localname)
(let ((tramp-ls-file-attributes
(format tramp-ls-file-attributes
(tramp-get-ls-command vec)
;; On systems which have no quoting style, file
;; names with special characters could fail.
(tramp-sh--quoting-style-options vec)
(tramp-get-ls-command vec)
(if (tramp-remote-selinux-p vec) "Z" "")
(tramp-sh--quoting-style-options vec)))
symlinkp dirp
res-inode res-filemodes res-numlinks
res-uid-string res-gid-string res-uid-integer res-gid-integer
res-size res-symlink-target res-context)
(tramp-maybe-send-script
vec tramp-ls-file-attributes "tramp_ls_file_attributes")
(when (tramp-send-command-and-check
vec (format "tramp_ls_file_attributes %s"
(tramp-shell-quote-argument localname)))
;; Parse `ls -l' output ...
(with-current-buffer (tramp-get-buffer vec)
(when (> (buffer-size) 0)
(goto-char (point-min))
;; ... inode
(setq res-inode (read (current-buffer)))
;; ... file mode flags
(setq res-filemodes (symbol-name (read (current-buffer))))
;; ... number links
(setq res-numlinks (read (current-buffer)))
;; ... uid and gid
(setq res-uid-string (read (current-buffer)))
(setq res-gid-string (read (current-buffer)))
(when (natnump res-uid-string)
(setq res-uid-string (number-to-string res-uid-string)))
(unless (stringp res-uid-string)
(setq res-uid-string (symbol-name res-uid-string)))
(when (natnump res-gid-string)
(setq res-gid-string (number-to-string res-gid-string)))
(unless (stringp res-gid-string)
(setq res-gid-string (symbol-name res-gid-string)))
;; ... size
(setq res-size (read (current-buffer)))
;; From the file modes, figure out other stuff.
(setq symlinkp (eq ?l (aref res-filemodes 0)))
(setq dirp (eq ?d (aref res-filemodes 0)))
;; If symlink, find out file name pointed to.
(when symlinkp
(search-forward "-> ")
(setq res-symlink-target
(if (looking-at-p "\"")
(read (current-buffer))
(buffer-substring (point) (line-end-position)))))
(forward-line)
;; ... file mode flags
(read (current-buffer))
;; ... number links
(read (current-buffer))
;; ... uid and gid
(setq res-uid-integer (read (current-buffer)))
(setq res-gid-integer (read (current-buffer)))
(unless (numberp res-uid-integer)
(setq res-uid-integer tramp-unknown-id-integer))
(unless (numberp res-gid-integer)
(setq res-gid-integer tramp-unknown-id-integer))
;; ... SELinux context
(when (tramp-remote-selinux-p vec)
(setq res-context (read (current-buffer))
res-context (symbol-name res-context)))
;; Return data gathered.
(list
;; 0. t for directory, string (name linked to) for symbolic
;; link, or nil.
(or dirp res-symlink-target)
;; 1. Number of links to file.
res-numlinks
;; 2. File uid.
(cons res-uid-string res-uid-integer)
;; 3. File gid.
(cons res-gid-string res-gid-integer)
;; 4. Last access time.
;; 5. Last modification time.
;; 6. Last status change time.
tramp-time-dont-know tramp-time-dont-know tramp-time-dont-know
;; 7. Size in bytes (-1, if number is out of range).
res-size
;; 8. File modes, as a string of ten letters or dashes as in ls -l.
res-filemodes
;; 9. t if file's gid would change if file were deleted and
;; recreated. Will be set in `tramp-convert-file-attributes'.
t
;; 10. Inode number.
res-inode
;; 11. Device number. Will be replaced by a virtual device number.
-1
;; 12. SELinux context. Will be extracted in
;; `tramp-convert-file-attributes'.
res-context))))))