Function: tramp-smb-get-file-entries

tramp-smb-get-file-entries is a byte-compiled function defined in tramp-smb.el.gz.

Signature

(tramp-smb-get-file-entries DIRECTORY)

Documentation

Read entries which match DIRECTORY.

Either the shares are listed, or the dir command is executed. Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR).

Source Code

;; Defined in /usr/src/emacs/lisp/net/tramp-smb.el.gz
;; Share names of a host are cached.  It is very unlikely that the
;; shares do change during connection.
(defun tramp-smb-get-file-entries (directory)
  "Read entries which match DIRECTORY.
Either the shares are listed, or the `dir' command is executed.
Result is a list of (LOCALNAME MODE SIZE MONTH DAY TIME YEAR)."
  ;; If CIFS capabilities are enabled, symlinks are not listed
  ;; by `dir'.  This is a consequence of
  ;; <https://www.samba.org/samba/news/symlink_attack.html>.  See also
  ;; <https://bugzilla.samba.org/show_bug.cgi?id=5116>.
  (with-parsed-tramp-file-name (file-name-as-directory directory) nil
    (setq localname (or localname "/"))
    (with-tramp-file-property v localname "file-entries"
      (let* ((share (tramp-smb-get-share v))
	     (cache (tramp-get-connection-property v "share-cache"))
	     res entry)

	(if (and (not share) cache)
	    ;; Return cached shares.
	    (setq res cache)

	  ;; Read entries.
	  (if share
	      (tramp-smb-send-command
	       v (format "dir %s*" (tramp-smb-shell-quote-localname v)))
	    ;; `tramp-smb-maybe-open-connection' lists also the share names.
	    (tramp-smb-maybe-open-connection v))

	  ;; Loop the listing.
	  (with-current-buffer (tramp-get-connection-buffer v)
	    (goto-char (point-min))
	    (if (search-forward-regexp tramp-smb-errors nil t)
		(tramp-error v 'file-error "%s `%s'" (match-string 0) directory)
	      (while (not (eobp))
		(setq entry (tramp-smb-read-file-entry share))
		(forward-line)
		(when entry (push entry res)))))

	  ;; Cache share entries.
	  (unless share
	    (tramp-set-connection-property v "share-cache" res)))

	;; Add directory itself.
	(push '("" "drwxrwxrwx" 0 (0 0)) res)

	;; Return entries.
	(delq nil res)))))