Function: tramp-sh-handle-directory-files-and-attributes

tramp-sh-handle-directory-files-and-attributes is a byte-compiled function defined in tramp-sh.el.gz.

Signature

(tramp-sh-handle-directory-files-and-attributes DIRECTORY &optional FULL MATCH NOSORT ID-FORMAT COUNT)

Documentation

Like directory-files-and-attributes for Tramp files.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-sh.el.gz
;; Directory listings.

(defun tramp-sh-handle-directory-files-and-attributes
  (directory &optional full match nosort id-format count)
  "Like `directory-files-and-attributes' for Tramp files."
  (unless id-format (setq id-format 'integer))
  (unless (file-exists-p directory)
    (tramp-compat-file-missing
     (tramp-dissect-file-name directory) directory))
  (when (file-directory-p directory)
    (setq directory (expand-file-name directory))
    (let* ((temp
	    (copy-tree
	     (with-parsed-tramp-file-name directory nil
	       (with-tramp-file-property
		   v localname
		   (format "directory-files-and-attributes-%s" id-format)
		 (mapcar
		  (lambda (x)
		    (cons (car x) (tramp-convert-file-attributes v (cdr x))))
		  (cond
		   ((tramp-get-remote-stat v)
		    (tramp-do-directory-files-and-attributes-with-stat
		     v localname id-format))
		   ((tramp-get-remote-perl v)
		    (tramp-do-directory-files-and-attributes-with-perl
		     v localname id-format))
		   (t nil)))))))
	   result item)

      (while temp
	(setq item (pop temp))
	(when (or (null match) (string-match-p match (car item)))
	  (when full
	    (setcar item (expand-file-name (car item) directory)))
	  (push item result)))

      (unless nosort
	(setq result (sort result (lambda (x y) (string< (car x) (car y))))))

      (when (and (natnump count) (> count 0))
	(setq result (nbutlast result (- (length result) count))))

      (or result
	  ;; The scripts could fail, for example with huge file size.
	  (tramp-handle-directory-files-and-attributes
	   directory full match nosort id-format count)))))