Function: tramp-skeleton-directory-files-and-attributes

tramp-skeleton-directory-files-and-attributes is a macro defined in tramp.el.gz.

Signature

(tramp-skeleton-directory-files-and-attributes DIRECTORY &optional FULL MATCH NOSORT ID-FORMAT COUNT &rest BODY)

Documentation

Skeleton for tramp-*-handle-directory-files-and-attributes.

BODY is the backend specific code.

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp.el.gz
(defmacro tramp-skeleton-directory-files-and-attributes
    (directory &optional full match nosort id-format count &rest body)
  "Skeleton for `tramp-*-handle-directory-files-and-attributes'.
BODY is the backend specific code."
  (declare (indent 6) (debug t))
  `(or
    (with-parsed-tramp-file-name (expand-file-name ,directory) nil
      (tramp-barf-if-file-missing v ,directory
	(when (file-directory-p ,directory)
	  (let ((temp
		 (copy-tree
		  (mapcar
		   (lambda (x)
		     (cons
		      (car x)
		      (tramp-convert-file-attributes
			  v (expand-file-name (car x) localname)
			  ,id-format (cdr x))))
		   (with-tramp-file-property
		       v localname "directory-files-and-attributes"
		     ,@body))))
		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 (tramp-compat-ntake ,count result)))

	    (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))))))

    ;; Error handling.
    (if (not (file-exists-p ,directory))
	(tramp-error
	 (tramp-dissect-file-name ,directory) 'file-missing ,directory)
      nil)))